Skip to content

Commit

Permalink
Refactor getting pull request (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
micnncim authored May 6, 2020
1 parent 883a016 commit 59afe90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2033,6 +2033,10 @@ function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const pull = yield getMergedPullRequest(core.getInput('github_token'), github.context.repo.owner, github.context.repo.repo, github.context.sha);
if (!pull) {
core.debug('pull request not found');
return;
}
core.setOutput('title', pull.title);
core.setOutput('body', pull.body);
core.setOutput('number', pull.number);
Expand All @@ -2058,7 +2062,7 @@ function getMergedPullRequest(githubToken, owner, repo, sha) {
});
const pull = resp.data.find(p => p.merge_commit_sha === sha);
if (!pull) {
throw new Error('pull request not found');
return null;
}
return {
title: pull.title,
Expand Down
8 changes: 6 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ async function run(): Promise<void> {
github.context.repo.repo,
github.context.sha
);
if (!pull) {
core.debug('pull request not found');
return;
}

core.setOutput('title', pull.title);
core.setOutput('body', pull.body);
Expand All @@ -34,7 +38,7 @@ async function getMergedPullRequest(
owner: string,
repo: string,
sha: string
): Promise<PullRequest> {
): Promise<PullRequest | null> {
const client = new github.GitHub(githubToken);

const resp = await client.pulls.list({
Expand All @@ -48,7 +52,7 @@ async function getMergedPullRequest(

const pull = resp.data.find(p => p.merge_commit_sha === sha);
if (!pull) {
throw new Error('pull request not found');
return null;
}

return {
Expand Down

0 comments on commit 59afe90

Please sign in to comment.