-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
97 lines (80 loc) · 3.17 KB
/
index.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const core = require('@actions/core');
const github = require('@actions/github');
const Git = require('./utils/git');
const Config = require('./utils/config');
const ReleaseTaggingAction = require('./actions/ReleaseTaggingAction');
const ReleasePullRequestAction = require('./actions/ReleasePullRequestAction');
const releaseTaggingAction = new ReleaseTaggingAction();
const releasePullRequestAction = new ReleasePullRequestAction();
const main = async () => {
const gitHelper = new Git();
try {
// Get Action Input Parameters
const token = core.getInput('token', { required: true });
const configPath = core.getInput('config-path', { required: true });
const action = core.getInput('action', { required: true });
let timezone = core.getInput('timezone', { required: false });
let releasePrefix = core.getInput('release-prefix', { required: false });
let releaseSuffix = core.getInput('release-suffix', { required: false });
if (timezone === '') {
timezone = '+0800';
} else {
timezone = timezone.replace(/[^0-9\+]/g, '');
}
const {
context: { payload: contextPayload, eventName }
} = github;
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
// Validate input parameters
if (eventName !== 'pull_request' || contextPayload.pull_request === undefined || contextPayload.action !== 'closed' || contextPayload.pull_request.merged !== true || contextPayload.pull_request.draft === true) {
console.log('ERROR :: This action should only be run on a closed pull request that has been merged');
process.exit(1);
}
const branch = contextPayload.pull_request.base.ref;
const octokit = new github.getOctokit(token);
// Load configuration file
await Config.loadConfig(octokit, owner, repo, configPath, contextPayload.pull_request.head.sha);
let tagsList;
// Get all previous tags
try {
const tagsListData = await octokit.rest.repos.listTags({
owner,
repo,
});
tagsList = tagsListData.data;
} catch (error) {
tagsList = [];
console.log(error.message);
}
console.log(JSON.stringify(tagsList));
if (action === 'release-pr') {
// Handling release pull request related logics
await releasePullRequestAction.execute({
gitHelper,
timezone,
releasePrefix,
releaseSuffix,
owner,
repo,
branch,
octokit,
tagsList
});
} else if (action === 'release') {
// Handling release tagging related action's logics
await releaseTaggingAction.execute({
gitHelper,
contextPayload,
releasePrefix,
owner,
repo,
branch,
octokit,
tagsList
});
}
} catch (error) {
core.setFailed(error.message);
}
}
main();