This commit is contained in:
Stephan 2022-01-10 20:00:34 +01:00
parent e0f2b0031a
commit eb36d5f680

View File

@ -53,7 +53,7 @@ module.exports = async ({github, context, core}) => {
// get and validate the event action // get and validate the event action
const eventAction = context.payload.action const eventAction = context.payload.action
if (false && eventAction != 'created' && eventAction != 'deleted') { if (eventAction != 'created' && eventAction != 'deleted') {
return return
} }
@ -72,16 +72,18 @@ module.exports = async ({github, context, core}) => {
}); });
const project = projectResponse.data const project = projectResponse.data
console.log(project) console.log(project)
const projectName = project.name // this! is the project name, we want a milestone with the same name const projectName = project.name
const cardId = context.payload.project_card.id // -- when a card is deleted it cannot be fetched!
const cardResponse = await restapi.projects.getCard({ //const cardId = context.payload.project_card.id
card_id: cardId //const cardResponse = await restapi.projects.getCard({
}) // card_id: cardId
const card = cardResponse.data //})
console.log(card) //const card = cardResponse.data
//console.log(card)
const [ itemType, itemNumber ] = last2(card.content_url) //const [ itemType, itemNumber ] = last2(card.content_url)
const [ itemType, itemNumber ] = last2(context.payload.project_card.content_url)
const isIssue = itemType == 'issues' const isIssue = itemType == 'issues'
const isPull = itemType == 'pulls' const isPull = itemType == 'pulls'
if (!isIssue && !isPull) { if (!isIssue && !isPull) {
@ -125,9 +127,10 @@ module.exports = async ({github, context, core}) => {
milestone = milestoneResponse.data milestone = milestoneResponse.data
} }
const milestoneId = milestone.id
const milestoneNumber = milestone.number const milestoneNumber = milestone.number
if (!item.milestone || item.milestone.number != milestoneNumber)
{
request = { request = {
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
@ -136,6 +139,7 @@ module.exports = async ({github, context, core}) => {
request[isIssue ? 'issue_number' : 'pull_number'] = itemNumber request[isIssue ? 'issue_number' : 'pull_number'] = itemNumber
await itemApi.update(request) await itemApi.update(request)
} }
}
else if (eventAction == 'deleted') { else if (eventAction == 'deleted') {
if (itemMilestone) { if (itemMilestone) {
console.log('remove milestone from issue/pull of deleted card') console.log('remove milestone from issue/pull of deleted card')