-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmain.ts
75 lines (66 loc) · 2.4 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
import * as core from '@actions/core'
import * as io from '@actions/io'
import * as inputHelper from 'checkout/lib/input-helper'
import {GitCommandManager} from './git-command-manager'
import * as gitSourceProvider from 'checkout/lib/git-source-provider'
import * as inputValidator from './input-validator'
import {PullsHelper} from './pulls-helper'
import {RebaseHelper} from './rebase-helper'
import {inspect} from 'util'
import {v4 as uuidv4} from 'uuid'
import * as utils from './utils'
async function run(): Promise<void> {
try {
const inputs = {
token: core.getInput('token'),
repository: core.getInput('repository'),
head: core.getInput('head'),
base: core.getInput('base'),
includeLabels: utils.getInputAsArray('include-labels'),
excludeLabels: utils.getInputAsArray('exclude-labels'),
excludeDrafts: core.getInput('exclude-drafts') === 'true'
}
core.debug(`Inputs: ${inspect(inputs)}`)
const [headOwner, head] = inputValidator.parseHead(inputs.head)
const pullsHelper = new PullsHelper(inputs.token)
const pulls = await pullsHelper.get(
inputs.repository,
head,
headOwner,
inputs.base,
inputs.includeLabels,
inputs.excludeLabels,
inputs.excludeDrafts
)
if (pulls.length > 0) {
core.info(`${pulls.length} pull request(s) found.`)
// Checkout
const path = uuidv4()
process.env['INPUT_PATH'] = path
process.env['INPUT_FETCH-DEPTH'] = '0'
process.env['INPUT_PERSIST-CREDENTIALS'] = 'true'
const sourceSettings = inputHelper.getInputs()
core.debug(`sourceSettings: ${inspect(sourceSettings)}`)
await gitSourceProvider.getSource(sourceSettings)
// Rebase
// Create a git command manager
const git = await GitCommandManager.create(sourceSettings.repositoryPath)
const rebaseHelper = new RebaseHelper(git)
let rebasedCount = 0
for (const pull of pulls) {
const result = await rebaseHelper.rebase(pull)
if (result) rebasedCount++
}
// Output count of successful rebases
core.setOutput('rebased-count', rebasedCount)
// Delete the repository
core.debug(`Removing repo at '${sourceSettings.repositoryPath}'`)
await io.rmRF(sourceSettings.repositoryPath)
} else {
core.info('No pull requests found.')
}
} catch (error: any) {
core.setFailed(error.message)
}
}
run()