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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ indent_size = 4
[{*.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
19 changes: 10 additions & 9 deletions __tests__/utils/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { addAssignees } from '../../src/utils/github';
describe('addAssignees', () => {
disableNetConnect(nock);

const logger = new Logger();
const logger = new Logger();
const octokit = new GitHub('test-token');

it('should do nothing 1', async() => {
const fn = jest.fn();
Expand All @@ -20,7 +21,7 @@ describe('addAssignees', () => {
return body;
});

await addAssignees(false, new GitHub(''), logger, getContext({
await addAssignees(false, octokit, logger, getContext({
repo: {
owner: 'hello',
repo: 'world',
Expand All @@ -39,7 +40,7 @@ describe('addAssignees', () => {
return body;
});

await addAssignees([], new GitHub(''), logger, getContext({
await addAssignees([], octokit, logger, getContext({
repo: {
owner: 'hello',
repo: 'world',
Expand All @@ -50,8 +51,8 @@ describe('addAssignees', () => {
});

it('should do nothing 3', async() => {
const fn1 = jest.fn();
const fn2 = jest.fn();
const fn1 = jest.fn();
const fn2 = jest.fn();
const mockStdout = spyOnStdout();
nock('https://api.github.com')
.post('/repos/hello/world/issues/1/assignees', body => {
Expand All @@ -67,7 +68,7 @@ describe('addAssignees', () => {

await addAssignees([
'test',
], new GitHub(''), logger, getContext({
], octokit, logger, getContext({
repo: {
owner: 'hello',
repo: 'world',
Expand All @@ -84,7 +85,7 @@ describe('addAssignees', () => {
});

it('should do nothing 4', async() => {
const fn = jest.fn();
const fn = jest.fn();
const mockStdout = spyOnStdout();
nock('https://api.github.com')
.post('/repos/hello/world/issues/1/assignees', body => {
Expand All @@ -99,7 +100,7 @@ describe('addAssignees', () => {

await expect(addAssignees([
'test',
], new GitHub(''), logger, getContext({
], octokit, logger, getContext({
repo: {
owner: 'hello',
repo: 'world',
Expand Down Expand Up @@ -130,7 +131,7 @@ describe('addAssignees', () => {

await addAssignees([
'test',
], new GitHub(''), logger, getContext({
], octokit, logger, getContext({
repo: {
owner: 'hello',
repo: 'world',
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
name: Assign Author

description: GitHub actions to assign author to issue or PR.

author: technote-space

inputs:
GITHUB_TOKEN:
description: Secret GitHub API token to use for making API requests.
required: true

branding:
icon: 'user-plus'
color: 'orange'

runs:
using: node12
main: lib/main.js
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@technote-space/assign-author",
"version": "1.2.5",
"version": "1.2.6",
"description": "GitHub actions to assign author to issue or PR.",
"author": "Technote <technote.space@gmail.com> (https://technote.space)",
"license": "MIT",
Expand All @@ -19,32 +19,32 @@
},
"main": "lib/main.js",
"dependencies": {
"@actions/core": "^1.2.0",
"@actions/github": "^2.0.0",
"@technote-space/filter-github-action": "^0.1.12",
"@technote-space/github-action-helper": "^0.6.25"
"@actions/core": "^1.2.2",
"@actions/github": "^2.1.0",
"@technote-space/filter-github-action": "^0.1.17",
"@technote-space/github-action-helper": "^0.8.2"
},
"devDependencies": {
"@technote-space/github-action-test-helper": "^0.0.27",
"@types/jest": "^24.0.23",
"@types/node": "^12.12.18",
"@typescript-eslint/eslint-plugin": "^2.11.0",
"@typescript-eslint/parser": "^2.11.0",
"eslint": "^6.7.2",
"jest": "^24.9.0",
"jest-circus": "^24.9.0",
"nock": "^11.7.0",
"ts-jest": "^24.2.0",
"typescript": "^3.7.3"
"@technote-space/github-action-test-helper": "^0.1.4",
"@types/jest": "^24.9.1",
"@types/node": "^13.5.0",
"@typescript-eslint/eslint-plugin": "^2.17.0",
"@typescript-eslint/parser": "^2.17.0",
"eslint": "^6.8.0",
"jest": "^25.1.0",
"jest-circus": "^25.1.0",
"nock": "^11.7.2",
"ts-jest": "^25.0.0",
"typescript": "^3.7.5"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsc",
"test": "yarn lint && yarn cover",
"lint": "eslint src/**/**/*.ts __tests__/**/**/*.ts",
"lint:fix": "eslint --fix src/**/**/*.ts __tests__/**/**/*.ts",
"lint": "eslint 'src/**/*.ts' '__tests__/**/*.ts'",
"lint:fix": "eslint --fix 'src/**/*.ts' '__tests__/**/*.ts'",
"cover": "jest --coverage",
"update": "ncu -u && yarn install && yarn upgrade && yarn audit"
}
Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import { setFailed, getInput } from '@actions/core';
import { setFailed } from '@actions/core';
import { context, GitHub } from '@actions/github';
import { isTargetEvent } from '@technote-space/filter-github-action';
import { Logger, ContextHelper } from '@technote-space/github-action-helper';
import { Logger, ContextHelper, Utils } from '@technote-space/github-action-helper';
import { getAssignees } from './utils/context';
import { addAssignees } from './utils/github';
import { TARGET_EVENTS } from './constant';
Expand All @@ -19,7 +19,7 @@ async function run(): Promise<void> {
return;
}

await addAssignees(getAssignees(context), new GitHub(getInput('GITHUB_TOKEN', {required: true})), logger, context);
await addAssignees(getAssignees(context), new GitHub(Utils.getAccessToken(true)), logger, context);
}

run().catch(error => setFailed(error.message));
2 changes: 2 additions & 0 deletions src/utils/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const getCurrentAssignees = (context: Context): string[] | false => {
if ('issues' === context.eventName) {
return context.payload.issue && 'assignees' in context.payload.issue ? context.payload.issue.assignees.map(assignee => assignee.login) : false;
}

if ('pull_request' === context.eventName) {
return context.payload.pull_request && 'assignees' in context.payload.pull_request ? context.payload.pull_request.assignees.map(assignee => assignee.login) : false;
}

return false;
};

Expand Down
Loading