diff --git a/__tests__/labeler.test.ts b/__tests__/labeler.test.ts index 64e8f684..681b59f8 100644 --- a/__tests__/labeler.test.ts +++ b/__tests__/labeler.test.ts @@ -1,5 +1,6 @@ import fs from 'fs'; import nock from 'nock'; +import {OctokitOptions} from '@octokit/core/dist-types/types'; import {Inputs} from '../src/context'; import {Labeler, LabelStatus} from '../src/labeler'; @@ -74,6 +75,11 @@ const cases = [ const orginalGitHubRepo = process.env.GITHUB_REPOSITORY; +const octokitOptions = { + retry: {enabled: false}, + throttle: {enabled: false} +} as OctokitOptions; + describe('run', () => { beforeAll(() => { process.env.GITHUB_REPOSITORY = 'crazy-max/ghaction-github-labeler'; @@ -95,7 +101,7 @@ describe('run', () => { .get(`/repos/crazy-max/ghaction-github-labeler/contents/${encodeURIComponent(input.yamlFile as string)}`) .reply(200, configFixture(input.yamlFile as string)); - const labeler = new Labeler(input); + const labeler = new Labeler(input, octokitOptions); await labeler.printRepoLabels(); console.log( (await labeler.labels).map(label => { @@ -166,7 +172,7 @@ describe('run', () => { .get(`/repos/crazy-max/ghaction-github-labeler/contents/${encodeURIComponent('.res/labels.merge1.yml')}`) .reply(200, configFixture('.res/labels.merge1.yml')); - const labeler = new Labeler(input); + const labeler = new Labeler(input, octokitOptions); const fileLabels = await labeler.fileLabels; expect(fileLabels.length).toBe(16); expect(fileLabels[15]).toEqual(expect.objectContaining({name: ':unicorn: Special'})); diff --git a/dist/index.js b/dist/index.js index 090a129f..41183059 100644 --- a/dist/index.js +++ b/dist/index.js @@ -125,8 +125,8 @@ var LabelStatus; LabelStatus[LabelStatus["Error"] = 6] = "Error"; })(LabelStatus = exports.LabelStatus || (exports.LabelStatus = {})); class Labeler { - constructor(inputs) { - const octokit = utils_1.GitHub.plugin(octokit_plugin_config_1.config); + constructor(inputs, options = {}) { + const octokit = utils_1.GitHub.plugin(octokit_plugin_config_1.config).defaults(options); this.octokit = new octokit(utils_1.getOctokitOptions(inputs.githubToken)); this.dryRun = inputs.dryRun; this.skipDelete = inputs.skipDelete; @@ -277,7 +277,7 @@ class Labeler { configs .map(config => { const labels = config.labels ? config.labels : config; - return { labels }; + return { labels: labels || [] }; }) .map(config => { config.labels.forEach(function (item) { diff --git a/src/labeler.ts b/src/labeler.ts index b2030986..a8ae60f3 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -5,7 +5,7 @@ import * as core from '@actions/core'; import {Inputs} from './context'; import {GitHub, getOctokitOptions, context} from '@actions/github/lib/utils'; import {config} from '@probot/octokit-plugin-config'; -import deepmerge from 'deepmerge'; +import {OctokitOptions} from '@octokit/core/dist-types/types'; export type Label = { name: string; color: string; @@ -39,8 +39,8 @@ export class Labeler { private readonly repoLabels: Promise; readonly fileLabels: Promise; - constructor(inputs: Inputs) { - const octokit = GitHub.plugin(config); + constructor(inputs: Inputs, options: OctokitOptions = {}) { + const octokit = GitHub.plugin(config).defaults(options); this.octokit = new octokit(getOctokitOptions(inputs.githubToken)); this.dryRun = inputs.dryRun; this.skipDelete = inputs.skipDelete; @@ -213,7 +213,7 @@ export class Labeler { configs .map(config => { const labels = config.labels ? config.labels : config; - return {labels}; + return {labels: labels || []}; }) .map(config => { config.labels.forEach(function (item: Label) {