Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ inputs:
description: A comma-separated list of keywords
default: depends on, blocked by

status_check_type:
required: false
description: >
The status check shown on a dependent PR whose merge is blocked,
either "pending" or "failure".
default: pending

comment:
required: false
description: A custom comment body. It supports `{{ dependencies }}` token.
Expand Down
14,910 changes: 7,454 additions & 7,456 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

127 changes: 62 additions & 65 deletions dist/licenses.txt

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

2 changes: 1 addition & 1 deletion dist/sourcemap-register.js

Large diffs are not rendered by default.

62 changes: 56 additions & 6 deletions src/__tests__/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DependencyResolver,
IssueManager,
formatDependency,
sanitizeStatusCheckInput,
} from '../helpers';

test('formatDependency', () => {
Expand All @@ -15,6 +16,18 @@ test('formatDependency', () => {
expect(formatDependency(dep, repo)).toEqual('#141');
});

describe('sanitizeStatusCheckInput', () => {
it('should default to "pending" on invalid input', () => {
expect(sanitizeStatusCheckInput('')).toEqual('pending');
expect(sanitizeStatusCheckInput('error')).toEqual('pending');
});

it('should return proper status check on valid input', () => {
expect(sanitizeStatusCheckInput('pending')).toEqual('pending');
expect(sanitizeStatusCheckInput('failure')).toEqual('failure');
});
});

test('DependencyExtractor', () => {
const repo = {
owner: 'github',
Expand Down Expand Up @@ -209,6 +222,7 @@ describe('IssueManager', () => {
actionName: 'my-action',
label: 'my-label',
commentSignature: '<action-signature>',
status_check_type: 'pending',
} as ActionContext['config'];

let listComments: jest.Mock<any, any>;
Expand Down Expand Up @@ -251,10 +265,9 @@ describe('IssueManager', () => {
};

beforeEach(() => {
((gh.rest.pulls.get as unknown) as jest.Mock<
any,
any
>).mockResolvedValue({ data: pr });
(
gh.rest.pulls.get as unknown as jest.Mock<any, any>
).mockResolvedValue({ data: pr });
});

it('ignores non-PRs', async () => {
Expand Down Expand Up @@ -283,7 +296,14 @@ describe('IssueManager', () => {
});
});

it('sets the correct status on pending', async () => {
it('sets the correct status if blocked and status_check_type input is "pending"', async () => {
let configWithStatus = {
...config,
status_check_type: 'pending',
} as ActionContext['config'];

manager = new IssueManager(gh, repo, configWithStatus);

const issue = { number: 141, pull_request: {} } as any;

await manager.updateCommitStatus(issue, [
Expand All @@ -302,7 +322,37 @@ describe('IssueManager', () => {
description: 'Blocked by owner/repo#999 and 2 more issues',
state: 'pending',
sha: pr.head.sha,
context: config.actionName,
context: configWithStatus.actionName,
});
});

it('sets the correct status if blocked and status_check_type input is "failure"', async () => {
let configWithStatus = {
...config,
status_check_type: 'failure',
} as ActionContext['config'];

manager = new IssueManager(gh, repo, configWithStatus);

const issue = { number: 141, pull_request: {} } as any;

await manager.updateCommitStatus(issue, [
{ repo: 'repo', owner: 'owner', number: 999, blocker: true },
{ blocker: true } as any,
{ blocker: true } as any,
]);

expect(gh.rest.pulls.get).toHaveBeenCalledWith({
...repo,
pull_number: issue.number,
});

expect(gh.rest.repos.createCommitStatus).toHaveBeenCalledWith({
...repo,
description: 'Blocked by owner/repo#999 and 2 more issues',
state: 'failure',
sha: pr.head.sha,
context: configWithStatus.actionName,
});
});
});
Expand Down
4 changes: 4 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Packages
import * as core from '@actions/core';
import * as github from '@actions/github';
import { sanitizeStatusCheckInput } from './helpers';

// Ours
import { ActionContext, GithubClient, Issue } from './types';
Expand All @@ -21,6 +22,9 @@ export async function getActionContext(): Promise<ActionContext> {
.trim()
.split(',')
.map((kw) => kw.trim()),
status_check_type: sanitizeStatusCheckInput(
core.getInput('status_check_type')
),
};

if (config.keywords.length === 0) {
Expand Down
12 changes: 11 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
GithubClient,
ActionContext,
Comment,
StatusCheck,
isValidStatusCheck,
} from './types';

export function formatDependency(dep: Dependency, repo?: Repository) {
Expand All @@ -23,6 +25,14 @@ export function formatDependency(dep: Dependency, repo?: Repository) {
return `${dep.owner}/${dep.repo}#${dep.number}`;
}

export function sanitizeStatusCheckInput(statusCheckInput: string) {
const statusCheck = isValidStatusCheck(statusCheckInput)
? statusCheckInput
: 'pending';

return statusCheck as StatusCheck;
}

export class DependencyExtractor {
private regex: RegExp;
private issueRegex = IssueRegex();
Expand Down Expand Up @@ -343,7 +353,7 @@ export class IssueManager {
description,
sha: pull.head.sha,
context: this.config.actionName,
state: isBlocked ? 'pending' : 'success',
state: isBlocked ? this.config.status_check_type : 'success',
});
}
}
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export type Dependency = Required<typeof github.context.issue> & {
};
export type Repository = Required<typeof github.context.repo>;

export const statusChecks = ['pending', 'failure'];
export type StatusCheck = 'pending' | 'failure';
export const isValidStatusCheck = (statusCheckInput: string) =>
statusChecks.includes(statusCheckInput);

export type ActionContext = {
client: GithubClient;
readOnlyClient: GithubClient;
Expand All @@ -32,5 +37,6 @@ export type ActionContext = {
check_issues: string;
ignore_dependabot: string;
keywords: string[];
status_check_type: StatusCheck;
};
};