Skip to content

Commit 63a977e

Browse files
Add mapping-kit labels and alert (#2867)
1 parent 139f434 commit 63a977e

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

.github/workflows/label-prs.yml

+43
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,46 @@ jobs:
6060
});
6161
await Promise.all(requests);
6262
}
63+
64+
- name: Comment for mapping-kit changes
65+
uses: actions/github-script@v7
66+
env:
67+
labelsToAdd: '${{ steps.compute-labels.outputs.add }}'
68+
labelsToRemove: '${{ steps.compute-labels.outputs.remove }}'
69+
with:
70+
script: |
71+
const { labelsToAdd, labelsToRemove, DRY_RUN } = process.env
72+
const shouldAddComment = labelsToAdd.length > 0 && labelsToAdd.split(",").some(x=>x.includes("mappingkit"))
73+
const shouldRemoveComment = labelsToRemove.length > 0 && labelsToRemove.split(",").some(x=>x.includes("mappingkit"))
74+
// Get the list of comments on the PR
75+
const response = await github.rest.issues.listComments({
76+
issue_number: context.issue.number,
77+
owner: context.repo.owner,
78+
repo: context.repo.repo
79+
})
80+
const mappingKitComment = response.data.find(comment => comment.body.includes('mapping-kit go'))
81+
if(shouldAddComment){
82+
if (mappingKitComment) {
83+
console.log('Already commented on this PR')
84+
return
85+
}
86+
// Add comment to the PR
87+
await github.rest.issues.createComment({
88+
issue_number: context.issue.number,
89+
owner: context.repo.owner,
90+
repo: context.repo.repo,
91+
body: `This PR makes changes to mapping-kit. Please ensure that the changes are reflected in the [mapping-kit go](https://github.com/segmentio/mapping-kit) library as well and link the PR in description.`
92+
})
93+
}
94+
if(shouldRemoveComment) {
95+
if (!mappingKitComment) {
96+
console.log('No mapping-kit comment to remove')
97+
return
98+
}
99+
// Remove comment from the PR
100+
await github.rest.issues.deleteComment({
101+
comment_id: mappingKitComment.id,
102+
owner: context.repo.owner,
103+
repo: context.repo.repo
104+
})
105+
}

scripts/github-action/compute-labels.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ async function computeFileBasedLabels(github, context, core) {
7070
const MODE_CLOUD_LABEL = 'mode:cloud'
7171
const MODE_DEVICE_LABEL = 'mode:device'
7272
const ACTIONS_CORE_LABEL = 'actions:core'
73+
const MAPPING_KIT_LABEL = 'actions:mappingkit'
7374

7475
const allLabels = [
7576
DEPLOY_REGISTRATION_LABEL,
7677
DEPLOY_PUSH_LABEL,
7778
MODE_CLOUD_LABEL,
7879
MODE_DEVICE_LABEL,
79-
ACTIONS_CORE_LABEL
80+
ACTIONS_CORE_LABEL,
81+
MAPPING_KIT_LABEL
8082
]
8183

8284
const newLabels = []
@@ -133,6 +135,12 @@ async function computeFileBasedLabels(github, context, core) {
133135
newLabels.push(DEPLOY_PUSH_LABEL)
134136
}
135137

138+
// Check if PR contains changes to mapping-kit
139+
const mappingKitRegex = /packages\/core\/src\/mapping\-kit\/.*/i
140+
if (files.some((file) => mappingKitRegex.test(file.filename))) {
141+
newLabels.push(MAPPING_KIT_LABEL)
142+
}
143+
136144
// Remove the existing custom labels if they are not required anymore
137145
const labelsToRemove = labels.filter((label) => allLabels.includes(label) && !newLabels.includes(label))
138146

0 commit comments

Comments
 (0)