Skip to content
Merged
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
2 changes: 1 addition & 1 deletion __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('main', () => {
'::endgroup::',
'==================================================',
'',
'> This is not target event.',
'> This is not a target event.',
]);
});

Expand Down
4 changes: 2 additions & 2 deletions __tests__/utils/process1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ describe('execute', () => {
'::group::Target PullRequest Ref [master]',
'::endgroup::',
'::group::Total:3 Succeeded:0 Failed:1 Skipped:2',
'> \x1b[33;40m→\x1b[0m\t[feature/new-topic3] This is not target branch',
'> \x1b[33;40m→\x1b[0m\t[feature/new-topic4] This is not target branch',
'> \x1b[33;40m→\x1b[0m\t[feature/new-topic3] This is not a target branch',
'> \x1b[33;40m→\x1b[0m\t[feature/new-topic4] This is not a target branch',
'> \x1b[31;40m×\x1b[0m\t[master] parameter [prBranchName] is required.',
'::set-output name=result::failed',
'::endgroup::',
Expand Down
12 changes: 6 additions & 6 deletions __tests__/utils/process2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ describe('execute', () => {
'[command]git diff \'HEAD..origin/change/new-topic2\' --name-only',
'::endgroup::',
'::group::Total:2 Succeeded:0 Failed:0 Skipped:2',
'> \x1b[33;40m✔\x1b[0m\t[change/new-topic1] This is close event',
'> \x1b[33;40m✔\x1b[0m\t[change/new-topic2] This is close event',
'> \x1b[33;40m✔\x1b[0m\t[change/new-topic1] This is a close event',
'> \x1b[33;40m✔\x1b[0m\t[change/new-topic2] This is a close event',
'::set-output name=result::not changed',
'::endgroup::',
]);
Expand Down Expand Up @@ -415,7 +415,7 @@ describe('execute', () => {
'[command]git diff \'HEAD..origin/change/new-topic1\' --name-only',
'::endgroup::',
'::group::Total:2 Succeeded:0 Failed:0 Skipped:2',
'> \x1b[33;40m✔\x1b[0m\t[change/new-topic1] This is close event',
'> \x1b[33;40m✔\x1b[0m\t[change/new-topic1] This is a close event',
'> \x1b[33;40m→\x1b[0m\t[change/new-topic2] duplicated (test/test-branch)',
'::set-output name=result::not changed',
'::endgroup::',
Expand Down Expand Up @@ -506,7 +506,7 @@ describe('execute', () => {
'::group::Target PullRequest Ref [change/new-topic2]',
'::endgroup::',
'::group::Total:2 Succeeded:0 Failed:1 Skipped:1',
'> \x1b[33;40m✔\x1b[0m\t[change/new-topic1] This is close event',
'> \x1b[33;40m✔\x1b[0m\t[change/new-topic1] This is a close event',
'> \x1b[31;40m×\x1b[0m\t[change/new-topic2] not found',
'::set-output name=result::failed',
'::endgroup::',
Expand Down Expand Up @@ -1100,8 +1100,8 @@ describe('execute', () => {
'[command]git push origin master:refs/heads/master',
'::endgroup::',
'::group::Total:3 Succeeded:1 Failed:0 Skipped:2',
'> \x1b[33;40m→\x1b[0m\t[change/new-topic1] This is not target branch',
'> \x1b[33;40m→\x1b[0m\t[change/new-topic2] This is not target branch',
'> \x1b[33;40m→\x1b[0m\t[change/new-topic1] This is not a target branch',
'> \x1b[33;40m→\x1b[0m\t[change/new-topic2] This is not a target branch',
'> \x1b[32;40m✔\x1b[0m\t[master] updated',
'::set-output name=result::succeeded',
'::endgroup::',
Expand Down
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@technote-space/github-action-pr-helper",
"version": "2.1.1",
"version": "2.1.2",
"description": "PullRequest Helper for GitHub Actions.",
"keywords": [
"github",
Expand Down Expand Up @@ -36,23 +36,24 @@
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/github": "^4.0.0",
"@technote-space/filter-github-action": "^0.5.8",
"@technote-space/github-action-helper": "^4.4.1",
"@octokit/openapi-types": "^2.0.0",
"@technote-space/filter-github-action": "^0.5.9",
"@technote-space/github-action-helper": "^4.4.4",
"moment": "^2.29.1"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@technote-space/github-action-test-helper": "^0.6.4",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.9",
"@typescript-eslint/eslint-plugin": "^4.8.2",
"@typescript-eslint/parser": "^4.8.2",
"eslint": "^7.14.0",
"husky": "^4.3.0",
"@technote-space/github-action-test-helper": "^0.6.5",
"@types/jest": "^26.0.16",
"@types/node": "^14.14.10",
"@typescript-eslint/eslint-plugin": "^4.9.0",
"@typescript-eslint/parser": "^4.9.0",
"eslint": "^7.15.0",
"husky": "^4.3.4",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"lint-staged": "^10.5.2",
"lint-staged": "^10.5.3",
"nock": "^13.0.5",
"ts-jest": "^26.4.4",
"typescript": "^4.1.2"
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function main(option: MainArguments): Promise<void> {

const octokit = Utils.getOctokit();
if (!await isTargetContext(octokit, await getActionContext(option))) {
getLogger(option.logger).info(option.notTargetEventMessage ?? 'This is not target event.');
getLogger(option.logger).info(option.notTargetEventMessage ?? 'This is not a target event.');
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export type PayloadPullsParams = {
[key: string]: any;
number: number;
'html_url'?: string;
body?: string;
body?: string | null;
};

export type PullsParams = PayloadPullsParams & {
Expand All @@ -89,14 +89,14 @@ export type PullsParams = PayloadPullsParams & {
ref: string;
user: {
login: string;
};
} | null;
};
base: {
repo: {
name: string;
owner: {
login: string;
};
} | null;
};
ref: string;
};
Expand Down
15 changes: 8 additions & 7 deletions src/utils/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Octokit} from '@technote-space/github-action-helper/dist/types';
import {GitHelper, Utils, ContextHelper, ApiHelper} from '@technote-space/github-action-helper';
import {Logger} from '@technote-space/github-action-log-helper';
import {RestEndpointMethods} from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/method-types';
import {PullsListResponseData} from '@octokit/types';
import {components} from '@octokit/openapi-types';
import {
getActionDetail,
isDisabledDeletePackage,
Expand All @@ -27,9 +27,10 @@ import {
} from './variables';
import {ActionContext, CommandOutput, ExecuteTask, Null} from '../types';

const {getWorkspace, useNpm, getOctokit} = Utils;
const {getLocalRefspec, getRefspec} = Utils;
const {getRepository, isPush} = ContextHelper;
type PullsListResponseData = components['schemas']['pull-request-simple'];
const {getWorkspace, getLocalRefspec, getRefspec} = Utils;
const {getOctokit, ensureNotNullValue, useNpm} = Utils;
const {getRepository, isPush} = ContextHelper;

export const getApiHelper = (octokit: Octokit, context: ActionContext, logger?: Logger, refForUpdate?: string): ApiHelper => new ApiHelper(octokit, context.actionContext, logger, {refForUpdate});

Expand Down Expand Up @@ -209,11 +210,11 @@ export const isMergeable = async(number: number, octokit: Octokit, context: Acti
owner: context.actionContext.repo.owner,
repo: context.actionContext.repo.repo,
'pull_number': number,
}), async() => (await (octokit as RestEndpointMethods).pulls.get({
}), async() => ensureNotNullValue((await (octokit as RestEndpointMethods).pulls.get({
owner: context.actionContext.repo.owner,
repo: context.actionContext.repo.repo,
'pull_number': number,
})).data.mergeable, context);
})).data.mergeable, false), context);

export const afterCreatePr = async(branchName: string, number: number, helper: GitHelper, logger: Logger, octokit: Octokit, context: ActionContext): Promise<void> => {
if (context.actionDetail.labels?.length) {
Expand Down Expand Up @@ -389,4 +390,4 @@ export const getNewMinorVersion = async(octokit: Octokit, context: ActionContext

export const getNewMajorVersion = async(octokit: Octokit, context: ActionContext): Promise<string> => getCache<string>(getCacheKey('new-major-version'), async() => await getApiHelper(octokit, context).getNewMajorVersion(), context);

export const findPR = async(branchName: string, octokit: Octokit, context: ActionContext): Promise<PullsListResponseData[number] | Null> => getCache(getCacheKey('pr', {branchName}), async() => getApiHelper(octokit, context).findPullRequest(branchName), context);
export const findPR = async(branchName: string, octokit: Octokit, context: ActionContext): Promise<PullsListResponseData | Null> => getCache(getCacheKey('pr', {branchName}), async() => getApiHelper(octokit, context).findPullRequest(branchName), context);
18 changes: 9 additions & 9 deletions src/utils/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import {getPrBranchName} from './variables';
import {INTERVAL_MS} from '../constant';
import {ActionContext, ProcessResult, AllProcessResult, PullsParams, CommandOutput} from '../types';

const {sleep, getBranch} = Utils;
const {isPr, isPush} = ContextHelper;
const commonLogger = new Logger(replaceDirectory);
const {sleep, getBranch, objectGet} = Utils;
const {isPr, isPush} = ContextHelper;
const commonLogger = new Logger(replaceDirectory);

const getResult = (result: 'succeeded' | 'failed' | 'skipped' | 'not changed', detail: string, context: ActionContext, fork?: string): ProcessResult => ({
result,
Expand Down Expand Up @@ -162,7 +162,7 @@ const createCommit = async(addComment: boolean, isClose: boolean, logger: Logger
}

if (isClose) {
return getResult('not changed', 'This is close event', context);
return getResult('not changed', 'This is a close event', context);
}

await push(branchName, helper, logger, context);
Expand Down Expand Up @@ -197,7 +197,7 @@ const noDiffProcess = async(branchName: string, isClose: boolean, logger: Logger
if (isClose) {
return {
mergeable: false,
result: getResult('not changed', 'This is close event', context),
result: getResult('not changed', 'This is a close event', context),
};
}

Expand Down Expand Up @@ -230,7 +230,7 @@ const diffProcess = async(files: string[], output: CommandOutput[], branchName:
if (isClose) {
return {
mergeable: false,
result: getResult('not changed', 'This is close event', context),
result: getResult('not changed', 'This is a close event', context),
};
}

Expand All @@ -246,7 +246,7 @@ const createPr = async(makeGroup: boolean, isClose: boolean, helper: GitHelper,
}

if (!isActionPr(context) && !await isTargetBranch(getPrHeadRef(context), octokit, context)) {
return getResult('skipped', 'This is not target branch', context);
return getResult('skipped', 'This is not a target branch', context);
}

if (isActionPr(context) || isNotCreatePR(context)) {
Expand Down Expand Up @@ -330,8 +330,8 @@ const runCreatePr = async(isClose: boolean, getPulls: (Octokit, ActionContext) =

for await (const pull of getPulls(octokit, context)) {
const actionContext = await getActionContext(pull, octokit, context);
if (pull.head.user.login !== context.actionContext.repo.owner) {
results.push(getResult('skipped', 'PR from fork', actionContext, pull.head.user.login));
if (objectGet(pull.head.user, 'login') !== context.actionContext.repo.owner) {
results.push(getResult('skipped', 'PR from fork', actionContext, objectGet(pull.head.user, 'login')));
continue;
}

Expand Down
Loading