Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
8398a7 committed Aug 10, 2020
2 parents a06627c + 5797d0c commit 85a0579
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
![](https://img.shields.io/github/v/release/8398a7/action-slack?color=brightgreen)
[![codecov](https://codecov.io/gh/8398a7/action-slack/branch/master/graph/badge.svg)](https://codecov.io/gh/8398a7/action-slack)


- [Document](https://action-slack.netlify.app)

## Quick Start
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "action-slack",
"version": "3.6.0",
"private": true,
"version": "3.6.1",
"description": "You can notify slack of GitHub Actions.",
"main": "lib/main.js",
"scripts": {
"build": "tsc",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"lint": "eslint src/**/*.ts",
"pack": "ncc build",
"pack": "ncc build -m",
"test": "jest && codecov",
"test-for-local": "jest",
"all": "npm run build && npm run format-check && npm run lint && npm run pack && npm test",
Expand Down
8 changes: 4 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const Custom = 'custom';
export const Always = 'always';
type AlwaysType = 'always';

export type GitHub = InstanceType<typeof GitHub>;
export type Octokit = InstanceType<typeof GitHub>;

export interface With {
status: string;
Expand All @@ -40,15 +40,15 @@ const subteamMention = 'subteam^';
export class Client {
private fieldFactory: FieldFactory;
private webhook: IncomingWebhook;
private github?: GitHub;
private octokit?: Octokit;
private with: With;

constructor(props: With, token?: string, webhookUrl?: string) {
this.with = props;
if (this.with.fields === '') this.with.fields = 'repo,commit';

if (token !== undefined) {
this.github = getOctokit(token);
this.octokit = getOctokit(token);
}

if (webhookUrl === undefined) {
Expand All @@ -58,7 +58,7 @@ export class Client {
this.fieldFactory = new FieldFactory(
this.with.fields,
this.jobName,
this.github,
this.octokit,
);
}

Expand Down
28 changes: 14 additions & 14 deletions src/fields.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { context } from '@actions/github';
import { GitHub } from './client';
import { Octokit } from './client';

export interface Field {
title: string;
Expand All @@ -8,14 +8,14 @@ export interface Field {
}

export class FieldFactory {
private github?: GitHub;
private octokit?: Octokit;
private fields: string[];
private jobName: string;

constructor(fields: string, jobName: string, github?: GitHub) {
constructor(fields: string, jobName: string, octokit?: Octokit) {
this.fields = fields.replace(/ /g, '').split(',');
this.jobName = jobName;
this.github = github;
this.octokit = octokit;
}

includes(field: string) {
Expand Down Expand Up @@ -71,12 +71,12 @@ export class FieldFactory {
}

private async message(): Promise<string> {
if (this.github === undefined) {
if (this.octokit === undefined) {
process.env.AS_MESSAGE = this.githubTokenIsNotSet;
return this.githubTokenIsNotSet;
}

const resp = await this.getCommit(this.github);
const resp = await this.getCommit(this.octokit);

const value = `<${resp.data.html_url}|${
resp.data.commit.message.split('\n')[0]
Expand All @@ -86,12 +86,12 @@ export class FieldFactory {
}

private async author(): Promise<string> {
if (this.github === undefined) {
if (this.octokit === undefined) {
process.env.AS_AUTHOR = this.githubTokenIsNotSet;
return this.githubTokenIsNotSet;
}

const resp = await this.getCommit(this.github);
const resp = await this.getCommit(this.octokit);
const author = resp.data.commit.author;

const value = `${author.name}<${author.email}>`;
Expand All @@ -100,12 +100,12 @@ export class FieldFactory {
}

private async took(): Promise<string> {
if (this.github === undefined) {
if (this.octokit === undefined) {
process.env.AS_JOB = this.githubTokenIsNotSet;
return this.githubTokenIsNotSet;
}

const resp = await this.github?.actions.listJobsForWorkflowRun({
const resp = await this.octokit?.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId,
Expand Down Expand Up @@ -139,13 +139,13 @@ export class FieldFactory {
}

private async job(): Promise<string> {
if (this.github === undefined) {
if (this.octokit === undefined) {
process.env.AS_JOB = this.githubTokenIsNotSet;
return this.githubTokenIsNotSet;
}

const { owner } = context.repo;
const resp = await this.github?.actions.listJobsForWorkflowRun({
const resp = await this.octokit?.actions.listJobsForWorkflowRun({
owner,
repo: context.repo.repo,
run_id: context.runId,
Expand Down Expand Up @@ -213,10 +213,10 @@ export class FieldFactory {
return value;
}

private async getCommit(github: GitHub) {
private async getCommit(octokit: Octokit) {
const { owner, repo } = context.repo;
const { sha: ref } = context;
return await github.repos.getCommit({ owner, repo, ref });
return await octokit.repos.getCommit({ owner, repo, ref });
}

private get githubTokenIsNotSet() {
Expand Down

0 comments on commit 85a0579

Please sign in to comment.