Skip to content

Commit ef980d5

Browse files
committed
fix: scope release project status transitions
1 parent b66dbf1 commit ef980d5

2 files changed

Lines changed: 35 additions & 30 deletions

File tree

.github/actions/project-board/transition-status/run.cjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,17 @@ module.exports = async function transitionStatus({ github, context, core }) {
7070
__typename
7171
... on Issue {
7272
number
73+
repository {
74+
nameWithOwner
75+
}
7376
title
7477
url
7578
}
7679
... on PullRequest {
7780
number
81+
repository {
82+
nameWithOwner
83+
}
7884
title
7985
url
8086
}
@@ -126,6 +132,12 @@ module.exports = async function transitionStatus({ github, context, core }) {
126132
return `Project item ${item.id}`;
127133
};
128134

135+
const belongsToCurrentRepository = (item) => {
136+
const repository = item.content?.repository?.nameWithOwner;
137+
138+
return `${context.repo.owner}/${context.repo.repo}` === repository;
139+
};
140+
129141
const moveToStatus = async (item, label) => {
130142
const currentStatus = board.getExistingFieldValue(item, 'Status');
131143

@@ -154,6 +166,12 @@ module.exports = async function transitionStatus({ github, context, core }) {
154166
let skippedCount = 0;
155167

156168
for (const item of await loadProjectItems()) {
169+
if (!belongsToCurrentRepository(item)) {
170+
skippedCount++;
171+
172+
continue;
173+
}
174+
157175
if (await moveToStatus(item, formatLabel(item))) {
158176
movedCount++;
159177

.github/actions/project-board/transition-status/run.test.cjs

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,22 @@ const project = {
2828
/**
2929
* @param {string} id
3030
* @param {string} status
31+
* @param {'Issue'|'PullRequest'} type
32+
* @param {number} number
33+
* @param {string} repository
3134
*
3235
* @returns {object}
3336
*/
34-
function projectItem(id, status) {
37+
function projectItem(id, status, type = 'Issue', number = 1, repository = 'php-fast-forward/dev-tools') {
3538
return {
3639
id,
40+
content: {
41+
__typename: type,
42+
number,
43+
repository: {
44+
nameWithOwner: repository,
45+
},
46+
},
3747
project: {
3848
id: project.id,
3949
},
@@ -157,27 +167,10 @@ async function withEnvironment(env, callback) {
157167

158168
test('moves items from multiple source statuses to the release status', async () => {
159169
const projectItems = [
160-
{
161-
...projectItem('current-pr', 'Release Prepared'),
162-
content: {
163-
__typename: 'PullRequest',
164-
number: 10,
165-
},
166-
},
167-
{
168-
...projectItem('merged-pr', 'Merged'),
169-
content: {
170-
__typename: 'PullRequest',
171-
number: 9,
172-
},
173-
},
174-
{
175-
...projectItem('backlog-issue', 'Backlog'),
176-
content: {
177-
__typename: 'Issue',
178-
number: 8,
179-
},
180-
},
170+
projectItem('current-pr', 'Release Prepared', 'PullRequest', 10),
171+
projectItem('merged-pr', 'Merged', 'PullRequest', 9),
172+
projectItem('foreign-merged-pr', 'Merged', 'PullRequest', 7, 'php-fast-forward/enum'),
173+
projectItem('backlog-issue', 'Backlog', 'Issue', 8),
181174
];
182175
const {github, mutations} = createGithub(projectItems);
183176
const {core, outputs} = createCore();
@@ -209,18 +202,12 @@ test('moves items from multiple source statuses to the release status', async ()
209202
assert.deepEqual(mutations.map((mutation) => mutation.itemId), ['current-pr', 'merged-pr']);
210203
assert.equal(outputs['source-statuses'], 'Release Prepared,Merged');
211204
assert.equal(outputs['moved-count'], '2');
212-
assert.equal(outputs['skipped-count'], '1');
205+
assert.equal(outputs['skipped-count'], '2');
213206
});
214207

215208
test('keeps the legacy from-status input supported', async () => {
216209
const projectItems = [
217-
{
218-
...projectItem('merged-issue', 'Merged'),
219-
content: {
220-
__typename: 'Issue',
221-
number: 8,
222-
},
223-
},
210+
projectItem('merged-issue', 'Merged', 'Issue', 8),
224211
];
225212
const {github, mutations} = createGithub(projectItems);
226213
const {core, outputs} = createCore();

0 commit comments

Comments
 (0)