Skip to content

Commit

Permalink
fix(github-actions): update merge status when target label changes
Browse files Browse the repository at this point in the history
Currently when a PR is retargeted, the assistant to the branch manager
does not trigger an update.
  • Loading branch information
devversion committed Dec 8, 2022
1 parent 51f34ba commit 2a121d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions github-actions/branch-manager/lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import * as core from '@actions/core';
import {context} from '@actions/github';
import {Octokit} from '@octokit/rest';
import {actionLabels} from '../../../ng-dev/pr/common/labels.js';
import {actionLabels, mergeLabels, targetLabels} from '../../../ng-dev/pr/common/labels.js';
import {revokeActiveInstallationToken, getAuthTokenFor, ANGULAR_ROBOT} from '../../utils.js';
import {
PullRequestLabeledEvent,
PullRequestEvent,
PushEvent,
} from '@octokit/webhooks-definitions/schema.js';

/** Set of target label names. */
const targetLabelNames = new Set(Object.values(targetLabels).map((t) => t.name));

async function run() {
if (context.eventName === 'push') {
const {ref} = context.payload as PushEvent;
Expand Down Expand Up @@ -50,7 +53,12 @@ async function run() {

if (context.payload.action === 'labeled') {
const event = context.payload as PullRequestLabeledEvent;
if (event.label.name === actionLabels.ACTION_MERGE.name) {
// If the merge label has been added, or if target labels have changed,
// another update of the merge status is needed.
if (
event.label.name === actionLabels.ACTION_MERGE.name ||
targetLabelNames.has(event.label.name)
) {
await createWorkflowForPullRequest();
}
}
Expand Down
3 changes: 2 additions & 1 deletion github-actions/branch-manager/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23509,6 +23509,7 @@ async function revokeActiveInstallationToken(githubOrToken) {
}

//
var targetLabelNames = new Set(Object.values(targetLabels).map((t) => t.name));
async function run() {
if (import_github2.context.eventName === "push") {
const { ref } = import_github2.context.payload;
Expand All @@ -23535,7 +23536,7 @@ async function run() {
}
if (import_github2.context.payload.action === "labeled") {
const event = import_github2.context.payload;
if (event.label.name === actionLabels.ACTION_MERGE.name) {
if (event.label.name === actionLabels.ACTION_MERGE.name || targetLabelNames.has(event.label.name)) {
await createWorkflowForPullRequest();
}
}
Expand Down

0 comments on commit 2a121d4

Please sign in to comment.