-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
50 lines (45 loc) · 2.21 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
const { handleNewPitch, handleNewScope, getProjectNodeItem } = require('./lib/onboarding')
const { parseIssueDescription, addScopeToBet } = require('./lib/scopes')
const { handleProgress, handleAtRisk } = require('./lib/progress')
const ITEM_ISSUE_TYPE = "Issue"
const KIND_FIELD = "Kind"
const PITCH_KIND_LABEL = "Pitch"
const BET_KIND_LABEL = "Bet"
module.exports = (app) => {
app.log.info("Yay, the app was loaded!")
app.on(["issues.edited", "issues.opened"], async (context) => {
const issueNumber = context.payload.issue.number
const owner = context.payload.repository.owner.login
const repo = context.payload.repository.name
const issueNodeId = context.payload.issue.node_id
const description = await parseIssueDescription(context)
if (description) {
await addScopeToBet(context, description)
await handleNewScope(context, owner, repo, issueNodeId, issueNumber)
}
})
app.on(["projects_v2_item.edited", "projects_v2_item.created"], async (context) => {
const projectNodeId = context.payload.projects_v2_item.project_node_id
const itemType = context.payload.projects_v2_item.content_type
const itemNodeId = context.payload.projects_v2_item.node_id
if (itemType === ITEM_ISSUE_TYPE) {
const item = await getProjectNodeItem(context, projectNodeId, itemNodeId)
const pitchType = item.fieldValues.nodes.find(item => item?.field?.name === KIND_FIELD && item?.name === PITCH_KIND_LABEL)
const betType = item.fieldValues.nodes.find(item => item?.field?.name === KIND_FIELD && item?.name === BET_KIND_LABEL)
const owner = item.content.repository.owner.login
const repository = item.content.repository.name
const issueNodeId = item.content.id
const issueNumber = item.content.number
if (pitchType || betType) {
await handleNewPitch(context, owner, repository, issueNodeId, issueNumber)
}
}
})
app.on("issue_comment.created", async(context) => {
const issueNumber = context.payload.issue.number
const owner = context.payload.repository.owner.login
const repo = context.payload.repository.name
await handleProgress(context, owner, repo, issueNumber)
await handleAtRisk(context, owner, repo, issueNumber)
})
};