1
0

test assign-milestone

This commit is contained in:
Stephan 2022-01-10 11:25:09 +01:00
parent 7c3bb81709
commit 1124d1661a
2 changed files with 163 additions and 0 deletions

123
.github/workflows/assign-milestones.js vendored Normal file
View File

@ -0,0 +1,123 @@
// get the project
// check if the name matches a version x.y or x.y.z
// created
// check that there is a corresponding milestone
// else create that milestone
// and assign the issue to the milestone
// deleted
// get the issue
// if issue is not closed,
// remove issue from milestone, if any
module.exports = ({github, context}) => {
const restapi = github.rest
// get and validate the event name
const eventName = github.event_name
if (eventName != 'project_card') {
return
}
// get and validate the event action
const eventAction = github.event.action
if (eventAction != 'created' && eventAction != 'deleted') {
return
}
// get and validate the card
const cardMeh = context.action.card_number
// get and validate the project
// get and validate the card item
//
if (eventAction == 'deleted') {
}
//const project_name = 'The API Team Board'
const project_name = 'test-project'
function firstOrDefault(items, predicate) {
for (const item of items) {
if (predicate(item)) {
return item
}
}
return null
}
// find the card
// find the type: issue, PR, note
// if issue or PR
// find corresponding milestone
// created if needed
// assign milestone
// madness - this is the only way we can explore context ?!
console.log(context);
console.log(context.payload);
return;
// find the project
console.log('find project...')
const projects = await restapi.projects.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo
})
console.log(`retrieved ${projects.data.length} projects.`)
const project = firstOrDefault(projects.data, (x) => x.name === project_name)
if (!project) {
core.setFailed(`Failed to find project "${project_name}".`)
return
}
else {
console.log(`project id: ${project.id}.`)
}
// determine content type
console.log('determine content type...')
const event_name = context.eventName
var content_type = null
if (event_name === 'issues') {
content_type = 'Issue'
}
if (event_name === 'pull_request') {
content_type = 'PullRequest'
}
if (!content_type) {
core.setFailed(`Unexpected event name "${event_name}".`)
return
}
else {
console.log(`content type: ${content_type}.`)
}
// get the issue/pr
console.log('get the issue/pr...')
const item = await restapi.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
})
if (!item) {
core.setFailed(`Failed to get issue ${context.issue.number}.`)
return
}
else {
console.log(`issue id: ${item.data.id}.`)
}
console.log('create the card...')
console.log(`in column ${column.id} for item ${item.data.id} of type ${content_type}`)
await restapi.projects.createCard({
column_id: column.id,
//note:,
content_id: item.data.id,
content_type: content_type
})
console.log('created')
}

40
.github/workflows/assign-milestones.yml vendored Normal file
View File

@ -0,0 +1,40 @@
name: Assign Milestones
on:
project_card:
# ignore: moved, converted, edited
types: [ created, deleted ]
jobs:
assign:
runs-on: ubuntu-latest
name: Assign
steps:
- name: Checkout
uses: actions/checkout
- name: Assign
uses: actions/github-script@v5
with:
github-token: ${{ secrets.MY_GITHUB_TOKEN_TESTREPO }}
script: |
# see https://github.com/actions/github-script
#
# github A pre-authenticated octokit/rest.js client with pagination plugins
# .rest The REST API (e.g. github.rest.issues.get(...) gets an issue)
# .request
# .paginate
# .graphql
# context An object containing the context of the workflow run
# see https://github.com/actions/toolkit/blob/main/packages/github/src/context.ts
# core A reference to the @actions/core package
# glob A reference to the @actions/glob package
# io A reference to the @actions/io package
# exec A reference to the @actions/exec package
# require A proxy wrapper around the normal Node.js require to enable requiring relative paths
# (relative to the current working directory) + requiring npm packages installed in the
# current working directory.
const script = require('./assign-milestone.js')
script({github, context})