fix
This commit is contained in:
parent
1da26533a1
commit
0b3a88b35a
92
.github/workflows/assign-milestones.js
vendored
92
.github/workflows/assign-milestones.js
vendored
|
@ -28,6 +28,15 @@ module.exports = async ({github, context, core}) => {
|
||||||
return [ s.substring(pos2 + 1, pos1), s.substring(pos1 + 1) ]
|
return [ s.substring(pos2 + 1, pos1), s.substring(pos1 + 1) ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function firstOrDefault(items, predicate) {
|
||||||
|
for (const item of items) {
|
||||||
|
if (predicate(item)) {
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
// insanely enough, due to the total lack of documentation, this
|
// insanely enough, due to the total lack of documentation, this
|
||||||
// is the best way one can figure out what exactly we are getting
|
// is the best way one can figure out what exactly we are getting
|
||||||
console.log(github)
|
console.log(github)
|
||||||
|
@ -73,37 +82,76 @@ module.exports = async ({github, context, core}) => {
|
||||||
console.log(card)
|
console.log(card)
|
||||||
|
|
||||||
const [ itemType, itemNumber ] = last2(card.content_url)
|
const [ itemType, itemNumber ] = last2(card.content_url)
|
||||||
var itemId
|
const isIssue = itemType == 'issues'
|
||||||
if (itemType == 'issues') {
|
const isPull = itemType == 'pulls'
|
||||||
const issueResponse = await restapi.issues.get({
|
if (!isIssue && !isPull) {
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
issue_number: itemNumber
|
|
||||||
})
|
|
||||||
console.log(issueResponse.data)
|
|
||||||
itemId = issueResponse.data.id
|
|
||||||
}
|
|
||||||
else if (itemType == 'pulls') {
|
|
||||||
const pullResponse = await restapi.pulls.get({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
pull_number: itemNumber
|
|
||||||
})
|
|
||||||
console.log(pullResponse.data)
|
|
||||||
itemId = pullResponse.data.id
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
core.setFailed(`Unsupported item type ${itemType}`)
|
core.setFailed(`Unsupported item type ${itemType}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log(`item: ${itemType}/${itemId}`)
|
const itemApi = isIssue ? restapi.issues : restapi.pulls
|
||||||
|
|
||||||
|
var request = {
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo
|
||||||
|
}
|
||||||
|
request[isIssue ? 'issue_number' : 'pull_number'] = itemNumber
|
||||||
|
|
||||||
|
const itemResponse = await itemApi.get(itemRequest)
|
||||||
|
const item = itemResponse.data
|
||||||
|
console.log(item)
|
||||||
|
const itemId = item.id
|
||||||
|
const itemMilestone = item.milestone
|
||||||
|
console.log(`item: ${itemType}/${itemId} milestone: ${itemMilestone == null ? '<none>' : itemMilestone}`)
|
||||||
|
|
||||||
|
if (eventAction == 'created') {
|
||||||
|
console.log('add or update milestone of issue/pull of created card')
|
||||||
|
|
||||||
const milestonesResponse = await restapi.issues.listMilestones({
|
const milestonesResponse = await restapi.issues.listMilestones({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo
|
||||||
})
|
})
|
||||||
const milestones = milestonesResponse.data
|
const milestones = milestonesResponse.data
|
||||||
console.log(milestones)
|
console.log(milestones)
|
||||||
|
var milestone = firstOrDefault(milestones, (x) => x.title == projectName)
|
||||||
|
|
||||||
|
if (!milestone) {
|
||||||
|
console.log(`create milestone '${projectName}'`)
|
||||||
|
const milestoneResponse = await restapi.issues.createMilestone({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
title: projectName
|
||||||
|
})
|
||||||
|
milestone = milestoneResponse.data
|
||||||
|
}
|
||||||
|
|
||||||
|
const milestoneId = milestone.id
|
||||||
|
|
||||||
|
request = {
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
milestone: milestoneId
|
||||||
|
}
|
||||||
|
request[isIssue ? 'issue_number' : 'pull_number'] = itemNumber
|
||||||
|
await itemApi.update(request)
|
||||||
|
}
|
||||||
|
else if (eventAction == 'deleted') {
|
||||||
|
if (itemMilestone) {
|
||||||
|
console.log('remove milestone from issue/pull of deleted card')
|
||||||
|
request = {
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo
|
||||||
|
}
|
||||||
|
request[isIssue ? 'issue_number' : 'pull_number'] = itemNumber
|
||||||
|
request.milestone = null
|
||||||
|
await itemApi.update(request)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log('deleted card had no milestone')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log(`nothing to do for evet action ${eventAction}`)
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user