-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
58 lines (49 loc) · 2.51 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
import * as Commander from 'commander'
import type * as Types from './sources/types.js'
import {ExportArgs, IsDebug} from './sources/debug.js'
import {ReplaceStringWithBooleanInObject} from './sources/utility.js'
import {GetLatestWorkflowTime} from './sources/actions.js'
import {ListBranches} from './sources/branches.js'
import {CommitManager} from './sources/commits.js'
import {PurgeRequestManager} from './sources/requests.js'
const Program = new Commander.Command()
// Set options.
Program.option('--debug', 'output extra debugging', false)
.option('--gh-token <TOKEN>', 'GitHub token', '')
.option('--repo <REPO>', 'A GitHub repository. eg: owner/repo', '')
.option('--workflow-ref <WORKFLOW_REF>', 'A GitHub workflow ref. eg: refs/heads/master', '')
.option('--branch <BRANCH>', 'A GitHub branch. eg: master', '')
.option('--ci-workspace-path <PATH>', 'A path to the CI workspace.', '')
.option('--ci-action-path <PATH>', 'A path to the CI action.', '')
.option('--should-use-api <TRUE_OR_FALSE>', 'Should use GitHub API?', 'false')
// Initialize Input of the options and export them.
Program.parse()
// Declare the options and print them if the debugging mode is enabled.
const ProgramRawOptions: Types.ProgramOptionsRawType = Program.opts()
if (IsDebug(ProgramRawOptions)) {
ExportArgs(ProgramRawOptions)
}
// Redefine with boolean.
const ProgramOptions = ReplaceStringWithBooleanInObject(ProgramRawOptions) as Types.ProgramOptionsType
// Workflow
const LatestWorkflowRunTime = await GetLatestWorkflowTime(ProgramOptions).then(LatestWorkflowRunTime => LatestWorkflowRunTime)
const Branches = await ListBranches(ProgramOptions).then(Branches => Branches)
const PurgeRequest = new PurgeRequestManager(ProgramOptions)
for (const Branch of Branches) {
const CommitManagerInstance = new CommitManager(ProgramOptions, Branches)
// eslint-disable-next-line no-await-in-loop
const CommitSHA = await CommitManagerInstance.GetCommitSHAFromLatestWorkflowTime(LatestWorkflowRunTime, Branch).then(CommitSHA => CommitSHA)
var ChangedFiles: string[] = []
if (CommitSHA.length === 0) {
continue
}
if (CommitSHA.length === 1) {
// eslint-disable-next-line no-await-in-loop
ChangedFiles = await CommitManagerInstance.GetChangedFilesFromACommit(CommitSHA.sha).then(ChangedFiles => ChangedFiles)
} else {
// eslint-disable-next-line no-await-in-loop
ChangedFiles = await CommitManagerInstance.GetChangedFilesFromSHAToHead(CommitSHA.sha, Branch).then(ChangedFiles => ChangedFiles)
}
PurgeRequest.AddURLs(ChangedFiles, Branch)
}
PurgeRequest.Start()