-
Notifications
You must be signed in to change notification settings - Fork 192
90 lines (81 loc) · 3.48 KB
/
assign-issue-milestone.yaml
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: Assign Issue Milestone
on:
push:
branches:
- main
paths-ignore:
- 'CHANGELOG.md'
- 'camel-quarkus-sbom/**'
permissions:
contents: read
issues: write
jobs:
assign-issue-milestone:
if: github.repository == 'apache/camel-quarkus'
runs-on: ubuntu-latest
steps:
- name: Assign Closed Issues To Latest Milestone
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const issueNumberFromCommitCommentRegex = new RegExp(`.*(?:fix(?:e[sd])?|(?:(?:resolve|close)[sd]?)):?\\s(?:https?:\\/\\/github\\.com\\/${context.repo.owner}\\/${context.repo.repo}\\/issues\\/|#)(\\d+)`, 'igm');
const issueNumbers = new Set();
// Get the commits that triggered this push event
const commitComparison = await github.rest.repos.compareCommitsWithBasehead({
owner: context.repo.owner,
repo: context.repo.repo,
basehead: `${context.payload.before}...${context.payload.after}`,
});
if (commitComparison && commitComparison.data) {
// Parse issue number references from commit comments
commitComparison.data.commits.forEach(commitData => {
for (const match of commitData.commit.message.matchAll(issueNumberFromCommitCommentRegex)) {
let issueNumber = parseInt(match[1]);
if (!isNaN(issueNumber)) {
issueNumbers.add(issueNumber);
}
}
});
}
// No issues associated with the merged PR so we can exit
if (issueNumbers.size === 0) {
return;
}
// Get open milestones
milestoneResults = await github.rest.issues.listMilestones({
owner: context.repo.owner,
repo: context.repo.repo,
sort: "title",
direction: "desc",
});
// Assign the latest milestone to issues associated with the merged PR
if (milestoneResults && milestoneResults.data.length > 0) {
const milestones = milestoneResults.data.filter(data => data.title.match("^[0-9]+.[0-9]+.[0-9]+.*"));
if (milestones && milestones.length > 0) {
const latestMilestone = milestones[0].number;
issueNumbers.forEach(issueNumber => {
github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
milestone: latestMilestone,
});
});
}
}