Skip to content

Commit

Permalink
[slack] Modify getCommit method option if event name is pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
homoluctus committed Nov 21, 2019
1 parent 5879c19 commit 57775e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11016,9 +11016,11 @@ class Block {
getCommitFields(token) {
return __awaiter(this, void 0, void 0, function* () {
const { owner, repo } = this.context.repo;
const { sha } = this.context;
const ref = this.isPullRequest
? this.context.ref.replace(/refs\/heads\//, '')
: this.context.sha;
const client = new github.GitHub(token);
const { data: commit } = yield client.repos.getCommit({ owner, repo, ref: sha });
const { data: commit } = yield client.repos.getCommit({ owner, repo, ref });
const authorName = commit.author.login;
const authorUrl = commit.author.html_url;
const commitMsg = commit.commit.message;
Expand Down
7 changes: 5 additions & 2 deletions src/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IncomingWebhookDefaultArguments
} from '@slack/webhook';
import {Context} from '@actions/github/lib/context';
import {thisExpression} from '@babel/types';

interface Accessory {
color: string;
Expand Down Expand Up @@ -90,12 +91,14 @@ class Block {
*/
public async getCommitFields(token: string): Promise<MrkdwnElement[]> {
const {owner, repo} = this.context.repo;
const {sha} = this.context;
const ref: string = this.isPullRequest
? this.context.ref.replace(/refs\/heads\//, '')
: this.context.sha;
const client: github.GitHub = new github.GitHub(token);
const {
data: commit
}: Octokit.Response<Octokit.ReposGetCommitResponse> = await client.repos.getCommit(
{owner, repo, ref: sha}
{owner, repo, ref}
);
const authorName: string = commit.author.login;
const authorUrl: string = commit.author.html_url;
Expand Down

0 comments on commit 57775e9

Please sign in to comment.