-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
56 lines (43 loc) 路 1.63 KB
/
Copy pathapp.js
File metadata and controls
56 lines (43 loc) 路 1.63 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
require('dotenv').config()
const packageInfo = require('./package.json')
console.log(`Starting ${packageInfo.name}`)
const helpers = require('./helpers')
const { Octokit } = require('@octokit/rest')
const octokit = new Octokit({
auth: `token ${process.env.GITHUB_TOKEN}`,
})
async function labelTopIssues() {
try {
//set variables
const numIssuesToLabel = process.env.TOP_NUMBER_OF_ISSUES || '10'
const eventLabelName = process.env.TOP_LABEL_NAME || '馃憤 Top 10 Issue'
const eventLabelColor = process.env.TOP_LABEL_COLOR || 'f442c2'
//set eventOwner and eventRepo based on action's env variables
const eventOwnerAndRepo = process.env.GITHUB_REPOSITORY
const eventOwner = helpers.getOwner(eventOwnerAndRepo)
const eventRepo = helpers.getRepo(eventOwnerAndRepo)
await helpers.createLabelInRepo(octokit, eventOwner, eventRepo, eventLabelName, eventLabelColor)
const issues = await helpers.getIssues(octokit, eventOwner, eventRepo)
let issuesToLabel = await helpers.getTopIssues(issues, '+1', numIssuesToLabel)
if (issuesToLabel) {
issuesToLabel.forEach((issue) => {
console.log('labeling issue #: ', issue.number)
helpers.addLabelToIssue(octokit, eventOwner, eventRepo, issue, eventLabelName)
})
}
const issuesWithLabel = await helpers.getIssues(octokit, eventOwner, eventRepo, eventLabelName)
helpers.pruneOldLabels(
octokit,
eventOwner,
eventRepo,
issuesToLabel,
issuesWithLabel,
eventLabelName
)
} catch (error) {
console.log(error)
}
}
//run the function
labelTopIssues()
module.exports.labelTopIssues = labelTopIssues