Repository navigation
Expand file tree
/
Copy pathmain.ts
More file actions
81 lines (71 loc) · 3.04 KB
/
Copy pathmain.ts
File metadata and controls
81 lines (71 loc) · 3.04 KB
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
import * as core from '@actions/core'
import { Octokit } from "@octokit/core"
import { getLabels } from './getLabels'
import { searchPRwithLabels } from './searchPRwithLabels'
import { searchCodePR } from './searchCodePR'
import { mergePR } from './mergePR'
import { postComment } from './postComment'
interface Input {
prNumber: number
repoName: string
owner: string
}
export async function main(octokit: Octokit, input: Input, merge: boolean): Promise<core.ExitCode> {
const prNumber = input.prNumber
const repoName = input.repoName
const owner = input.owner
core.info(`PR Number: ${prNumber}`)
core.info(`Repo Name: ${repoName}`)
try {
const labels = await getLabels(octokit, prNumber, repoName, owner)
core.info(`Labels: ${labels}`)
const labelsToSearch = labels.filter((label) => !label.endsWith("-pro"))
const PRs = await searchPRwithLabels(octokit, repoName, owner, labelsToSearch)
const otherPRs = PRs.filter((id) => id !== prNumber)
core.info(`Found PRs: ${PRs}`)
const codePR = await searchCodePR(octokit, prNumber, repoName, owner)
if (otherPRs.length > 0) {
const actor = process.env.GITHUB_ACTOR
const message = `${actor ? `@${actor}: ` : ''}Other open PRs found for these labels: ${otherPRs}. Nothing to merge yet.`
core.info(message)
if (codePR) {
await postComment(octokit, codePR.number, codePR.base.repo.name, codePR.base.repo.owner.login, message)
} else {
core.warning(`Could not identify original code PR for ${repoName}#${prNumber}. Cannot post comment.`)
}
return core.ExitCode.Success
} else {
core.info('No other open PRs found, proceeding to merge original code PR')
if (!codePR) {
core.warning(`Could not identify original code PR for ${repoName}#${prNumber}. Verify title/body format.`)
return core.ExitCode.Success
}
core.info(`Found original PR: ${codePR.base.repo.name}#${codePR.number}`)
if (merge) {
return mergePR(octokit, codePR.number, codePR.base.repo.name, owner).then((mergeResult) => {
core.info(`Merge Result: ${mergeResult}`)
if (mergeResult === undefined) {
core.setFailed(`Merge PR failed`)
return core.ExitCode.Failure
}
return core.ExitCode.Success
})
}
return core.ExitCode.Success
}
} catch (error) {
core.setFailed(error.message)
return Promise.resolve(core.ExitCode.Failure)
}
}
try {
const prNumber = parseInt(core.getInput('pr_number'))
const repoName = core.getInput('repo_name')
const owner = core.getInput('owner')
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN
})
main(octokit, { prNumber, repoName, owner }, true)
} catch (error) {
core.setFailed(error.message)
}