Skip to content

Commit 5d4fc35

Browse files
authored
Merge pull request #22 from banyan/fix-labelable-ids
Fix labelIds handling
2 parents 86c0a05 + 8bd5473 commit 5d4fc35

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

dist/entrypoint.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async function run() {
6868
}, {});
6969
util_1.logger.debug('allLabels', allLabels);
7070
const currentLabelNames = new Set(result.repository.pullRequest.labels.edges.map((edge) => edge.node.name));
71-
util_1.logger.debug('currentLabelNames', currentLabelNames);
71+
util_1.logger.debug('currentLabelNames', Array.from(currentLabelNames));
7272
const { headRefOid, baseRefOid } = result.repository.pullRequest;
7373
const { stdout } = await exec(`git fetch && git merge-base --is-ancestor ${baseRefOid} ${headRefOid} && git diff --name-only ${baseRefOid} || git diff --name-only $(git merge-base ${baseRefOid} ${headRefOid})`);
7474
const diffFiles = stdout.trim().split('\n');
@@ -82,11 +82,13 @@ async function run() {
8282
});
8383
return acc;
8484
}, []));
85+
util_1.logger.debug('newLabelNames', newLabelNames);
8586
const ruledLabelNames = new Set(Object.keys(config.rules));
8687
const labelNamesToAdd = new Set([...newLabelNames].filter(labelName => !currentLabelNames.has(labelName)));
8788
const labelNamesToRemove = new Set([...currentLabelNames].filter((labelName) => !newLabelNames.has(labelName) && ruledLabelNames.has(labelName)));
88-
util_1.logger.debug('labelNamesToAdd', labelNamesToAdd);
89-
util_1.logger.debug('labelNamesToRemove', labelNamesToRemove);
89+
util_1.logger.debug('ruledLabelNames', Array.from(ruledLabelNames));
90+
util_1.logger.debug('labelNamesToAdd', Array.from(labelNamesToAdd));
91+
util_1.logger.debug('labelNamesToRemove', Array.from(labelNamesToRemove));
9092
const labelableId = result.repository.pullRequest.id;
9193
util_1.logger.debug('labelableId', labelableId);
9294
if (labelNamesToAdd.size > 0) {
@@ -132,7 +134,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
132134
const tslib_1 = require("tslib");
133135
const core = tslib_1.__importStar(require("@actions/core"));
134136
const lodash_pick_1 = tslib_1.__importDefault(require("lodash.pick"));
135-
exports.getLabelIds = (allLabels, labelNames) => JSON.stringify(Object.values(lodash_pick_1.default(allLabels, labelNames)));
137+
exports.getLabelIds = (allLabels, labelNames) => Object.values(lodash_pick_1.default(allLabels, labelNames));
136138
exports.logger = {
137139
debug: (message, object) => {
138140
return core.debug(`${message}: ${JSON.stringify(object)}`);
@@ -190,7 +192,7 @@ exports.getPullRequestAndLabels = (graphqlWithAuth, { owner, repo, number, }) =>
190192
};
191193
exports.addLabelsToLabelable = (graphqlWithAuth, { labelIds, labelableId, }) => {
192194
const query = `
193-
mutation addLabelsToLabelable($labelIds: String!, $labelableId: String!) {
195+
mutation addLabelsToLabelable($labelIds: [ID!]!, $labelableId: ID!) {
194196
addLabelsToLabelable(input: {labelIds:$labelIds, labelableId:$labelableId}) {
195197
clientMutationId
196198
}
@@ -203,7 +205,7 @@ exports.addLabelsToLabelable = (graphqlWithAuth, { labelIds, labelableId, }) =>
203205
};
204206
exports.removeLabelsFromLabelable = (graphqlWithAuth, { labelIds, labelableId, }) => {
205207
const query = `
206-
mutation removeLabelsFromLabelable($labelIds: String!, $labelableId: String!) {
208+
mutation removeLabelsFromLabelable($labelIds: [ID!]!, $labelableId: ID!) {
207209
removeLabelsFromLabelable(input: {labelIds:$labelIds, labelableId:$labelableId}) {
208210
clientMutationId
209211
}

src/entrypoint.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async function run() {
9393
),
9494
);
9595

96-
logger.debug('currentLabelNames', currentLabelNames);
96+
logger.debug('currentLabelNames', Array.from(currentLabelNames));
9797

9898
const { headRefOid, baseRefOid } = result.repository.pullRequest;
9999

@@ -118,6 +118,8 @@ async function run() {
118118
}, []),
119119
);
120120

121+
logger.debug('newLabelNames', newLabelNames);
122+
121123
const ruledLabelNames = new Set(Object.keys(config.rules));
122124

123125
const labelNamesToAdd = new Set(
@@ -133,8 +135,9 @@ async function run() {
133135
),
134136
);
135137

136-
logger.debug('labelNamesToAdd', labelNamesToAdd);
137-
logger.debug('labelNamesToRemove', labelNamesToRemove);
138+
logger.debug('ruledLabelNames', Array.from(ruledLabelNames));
139+
logger.debug('labelNamesToAdd', Array.from(labelNamesToAdd));
140+
logger.debug('labelNamesToRemove', Array.from(labelNamesToRemove));
138141

139142
const labelableId = result.repository.pullRequest.id;
140143

src/query.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Label } from './interface';
12
import { graphql } from '@octokit/graphql';
23
import * as OctokitTypes from '@octokit/types';
34

@@ -66,12 +67,12 @@ export const addLabelsToLabelable = (
6667
labelIds,
6768
labelableId,
6869
}: {
69-
labelIds: string;
70+
labelIds: (Label | undefined)[];
7071
labelableId: string;
7172
},
7273
) => {
7374
const query = `
74-
mutation addLabelsToLabelable($labelIds: String!, $labelableId: String!) {
75+
mutation addLabelsToLabelable($labelIds: [ID!]!, $labelableId: ID!) {
7576
addLabelsToLabelable(input: {labelIds:$labelIds, labelableId:$labelableId}) {
7677
clientMutationId
7778
}
@@ -90,12 +91,12 @@ export const removeLabelsFromLabelable = (
9091
labelIds,
9192
labelableId,
9293
}: {
93-
labelIds: string;
94+
labelIds: (Label | undefined)[];
9495
labelableId: string;
9596
},
9697
) => {
9798
const query = `
98-
mutation removeLabelsFromLabelable($labelIds: String!, $labelableId: String!) {
99+
mutation removeLabelsFromLabelable($labelIds: [ID!]!, $labelableId: ID!) {
99100
removeLabelsFromLabelable(input: {labelIds:$labelIds, labelableId:$labelableId}) {
100101
clientMutationId
101102
}

src/util.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import * as core from '@actions/core';
22
import pick from 'lodash.pick';
33

44
import { Label, LabelName } from './interface';
5-
export const getLabelIds = (
6-
allLabels: Label[],
7-
labelNames: LabelName[],
8-
): string => JSON.stringify(Object.values(pick(allLabels, labelNames)));
5+
export const getLabelIds = (allLabels: Label[], labelNames: LabelName[]) =>
6+
Object.values(pick(allLabels, labelNames));
97

108
export const logger = {
119
debug: (message: string, object: {} | null | undefined) => {

0 commit comments

Comments
 (0)