Skip to content

Commit

Permalink
Merge pull request #12 from technote-space/release/v1.0.2
Browse files Browse the repository at this point in the history
release/v1.0.2
  • Loading branch information
technote-space committed Aug 27, 2019
2 parents 3368b73 + b3379d4 commit 558eb1f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ async function run() {

const project = await getProjectName(context.payload.project_card.id, octokit);
const column = await getColumnName(context.payload.project_card.column_id, octokit);
signale.info(`Target project: ${project}`);
signale.info(`Target column: ${column}`);

const labelsToRemove = getRemoveLabels(project, column, config);
const labelsToAdd = getAddLabels(project, column, config);
const issue = getRelatedIssue(context.payload, octokit);
Expand Down
12 changes: 8 additions & 4 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import path from 'path';
import signale from 'signale';
import {GitHub} from '@actions/github/lib/github';
import {Context} from '@actions/github/lib/context';
import {parseConfig} from './misc';
import {CONFIG_PATH} from '../constant';

export const getConfig: Function = async (fileName: string, octokit: GitHub, context: Context) => parseConfig(
(await octokit.repos.getContents({
export const getConfig: Function = async (fileName: string, octokit: GitHub, context: Context) => {
signale.info('Downloading config file: %s', path.posix.join(CONFIG_PATH, fileName));

const configFile = await octokit.repos.getContents({
owner: context.repo.owner,
repo: context.repo.repo,
path: path.posix.join(CONFIG_PATH, fileName),
})).data.content,
);
});
return parseConfig(configFile.data.content);
};
7 changes: 7 additions & 0 deletions src/utils/issue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import signale from 'signale';
import {GitHub} from '@actions/github/lib/github';
import {Context} from '@actions/github/lib/context';

export const getRelatedIssue: Function = async (payload: object, octokit: GitHub) => {
signale.info('Getting related issue');

const cardId = payload['project_card'].id;
const {data: {content_url: contentUrl}} = await octokit.projects.getCard({card_id: cardId});
const match = contentUrl.match(/issues\/(\d+)$/);
Expand All @@ -12,6 +15,8 @@ export const getRelatedIssue: Function = async (payload: object, octokit: GitHub
};

export const addLabels: Function = async (issue: number, labels: string[], octokit: GitHub, context: Context) => {
signale.info('Adding labels');

await octokit.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
Expand All @@ -21,6 +26,8 @@ export const addLabels: Function = async (issue: number, labels: string[], octok
};

export const removeLabels: Function = async (issue: number, labels: string[], octokit: GitHub, context: Context) => {
signale.info('Removing labels');

await Promise.all(labels.map(label => octokit.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down
5 changes: 5 additions & 0 deletions src/utils/misc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import yaml from 'js-yaml';
import signale from 'signale';
import {getInput} from '@actions/core' ;
import {GitHub} from '@actions/github/lib/github';
import {Context} from '@actions/github/lib/context';
Expand All @@ -9,11 +10,15 @@ export const isTargetEvent = (context: Context) => TARGET_EVENT_NAME === context
export const parseConfig = (content: string) => yaml.safeLoad(Buffer.from(content, 'base64').toString()) || {};

export const getProjectName = async (projectId: number, octokit: GitHub) => {
signale.info('Getting project name');

const {data: {name}} = await octokit.projects.get({project_id: projectId});
return name;
};

export const getColumnName = async (columnId: number, octokit: GitHub) => {
signale.info('Getting column name');

const {data: {name}} = await octokit.projects.getColumn({column_id: columnId});
return name;
};
Expand Down

0 comments on commit 558eb1f

Please sign in to comment.