This is an automated email from the ASF dual-hosted git repository. sjaranowski pushed a commit to branch v4 in repository https://gitbox.apache.org/repos/asf/maven-gh-actions-shared.git
The following commit(s) were added to refs/heads/v4 by this push: new 01cbef7 PR Automation allow assign milestone to branch 01cbef7 is described below commit 01cbef79a8d34bb8f07ae1e9ea1ce1e9351ea8cf Author: Slawomir Jaranowski <s.jaranow...@gmail.com> AuthorDate: Tue Jan 7 23:37:27 2025 +0100 PR Automation allow assign milestone to branch There are projects that we have multiple branches under maintenance --- .github/workflows/pr-automation.yml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr-automation.yml b/.github/workflows/pr-automation.yml index 53de48d..aab56a9 100644 --- a/.github/workflows/pr-automation.yml +++ b/.github/workflows/pr-automation.yml @@ -95,22 +95,29 @@ jobs: }); console.log(milestones); + const branch = context.payload.pull_request.base.ref - if ( milestones.data.length == 0 ) { + if (milestones.data.length == 0) { throw new Error('There are no open milestones ... please create one') } - if ( milestones.data.length > 1 ) { - throw new Error('There are more then oen open milestones ... please choose manually') + var milestone; + if (milestones.data.length > 1) { + milestone = milestones.data.find(({description}) => description.includes('branch: ' + branch)); + if (!milestone) { + throw new Error('There are more then oen open milestones ... please add a "branch: ' + branch + '" to description in one milestone'); + } + } else { + milestone = milestones.data[0]; } - console.log('Set milestone to: ' + milestones.data[0].title); + console.log('Set milestone to: ' + milestone.title); const result = await github.rest.issues.update({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, - milestone: milestones.data[0].number + milestone: milestone.number }); console.log(result);