Skip to content

Commit

Permalink
disable octokit throttling in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jetersen committed Jan 8, 2021
1 parent c262250 commit 3ab61b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
10 changes: 8 additions & 2 deletions __tests__/labeler.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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';
Expand All @@ -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 => {
Expand Down Expand Up @@ -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'}));
Expand Down
6 changes: 3 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -39,8 +39,8 @@ export class Labeler {
private readonly repoLabels: Promise<Label[]>;
readonly fileLabels: Promise<Label[]>;

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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3ab61b3

Please sign in to comment.