diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts
index 315d725..c3a8273 100644
--- a/__tests__/main.test.ts
+++ b/__tests__/main.test.ts
@@ -34,7 +34,6 @@ function pullRequestEventContext(overrides = {}): object {
head: {
ref: 'topic'
},
- labels: [],
number: 1,
user: {
login: 'lerebear'
@@ -51,10 +50,12 @@ describe('action', () => {
jest.spyOn(github, 'getOctokit').mockImplementation((token: string): any => {
if (token === 'xxx') {
return {
+ paginate: () => [],
rest: {
issues: {
getLabel: () => {},
- addLabels: () => {}
+ addLabels: () => {},
+ listComments: () => {}
}
}
}
diff --git a/badges/coverage.svg b/badges/coverage.svg
index 2bd6b8f..337ea38 100644
--- a/badges/coverage.svg
+++ b/badges/coverage.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/dist/index.js b/dist/index.js
index 9f2f46b..df21989 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -16912,7 +16912,12 @@ async function applyLabel(pull, score, config) {
const newLabelName = `${labelPrefix}${score.category.label.name}`;
const labelsToAdd = [newLabelName];
const labelsToRemove = [];
- for (const existingLabel of pull.labels) {
+ const existingLabels = await octokit.paginate(octokit.rest.issues.listLabelsOnIssue, {
+ owner: pull.base.repo.owner.login,
+ repo: pull.base.repo.name,
+ issue_number: pull.number
+ });
+ for (const existingLabel of existingLabels) {
if (existingLabel.name === newLabelName) {
labelsToAdd.pop();
}
diff --git a/src/main.ts b/src/main.ts
index 3b8f2d7..eca889e 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -180,6 +180,7 @@ async function applyLabel(
config: Configuration
): Promise {
const octokit = github.getOctokit(core.getInput('token'))
+
const labelPrefix = configOrDefault(
config.labeling?.categoryLabelPrefix,
DEFAULT_LABEL_PREFIX
@@ -188,7 +189,15 @@ async function applyLabel(
const labelsToAdd = [newLabelName]
const labelsToRemove = []
- for (const existingLabel of pull.labels) {
+ const existingLabels = await octokit.paginate(
+ octokit.rest.issues.listLabelsOnIssue,
+ {
+ owner: pull.base.repo.owner.login,
+ repo: pull.base.repo.name,
+ issue_number: pull.number
+ }
+ )
+ for (const existingLabel of existingLabels) {
if (existingLabel.name === newLabelName) {
labelsToAdd.pop()
} else if (existingLabel.name.startsWith(labelPrefix)) {