-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
65 lines (51 loc) · 1.64 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import simpleGit from 'simple-git'
import * as core from '@actions/core'
import * as github from '@actions/github'
import process from 'process'
import * as exec from '@actions/exec'
import { generateChangelog } from './generateChangelog'
// Get the current branch from the GITHUB_REF environment variable
let currentBranch = process.env.GITHUB_REF
// let currentBranch = 'test'
// Get the default branch from the github context
let defaultBranch: string = github.context.payload.repository?.default_branch
// let defaultBranch: string = 'main'
console.log('Default branch is: ' + defaultBranch)
let changelog: string = ''
// Check if the current branch exists
if (currentBranch) {
currentBranch = currentBranch.replace('refs/heads/', '')
console.log('Current branch is: ' + currentBranch)
} else {
core.setFailed('Could not determine the current branch')
}
if (!defaultBranch) {
core.setFailed('Could not determine the default branch')
}
// Get the default branch from the github context
if (!defaultBranch) {
core.setFailed('Could not determine the default branch')
}
async function run() {
const git = simpleGit();
const log = await git.log({
from: defaultBranch,
to: currentBranch,
splitOn: '..', // Split on two dots
format: {
hash: '%H',
date: '%aI',
message: '%s',
refNames: '%D',
body: '%b',
authorName: '%aN',
authorEmail: '%aE'
}
});
// Process commits and generate Markdown
changelog = generateChangelog(log.all);
console.log(changelog)
}
run()
// Set the CHANGELOG environment variable
core.exportVariable('CHANGELOG', changelog)