Skip to content

Commit

Permalink
fix: comment payload should not sync labels
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxingloh committed Jan 26, 2021
1 parent f61aea1 commit d756102
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ version: v1
labels:
- label: "feat"
sync: true # remove label if match failed, default: false
sync: true # remove label if match failed, default: false (pull_request/issue only)
matcher:
# Matcher will match on any 6 matcher
title: "^feat:.*"
Expand Down
8 changes: 8 additions & 0 deletions __tests__/labeler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ describe('mergeLabels, empty config', () => {
}

it('lhs empty should join', function () {
github.context.eventName = 'pull_request'
github.context.payload = {
pull_request: {
number: 1,
Expand All @@ -173,6 +174,7 @@ describe('mergeLabels, empty config', () => {

it('rhs empty should join', function () {
const labels = ['a', 'b', 'c']
github.context.eventName = 'pull_request'
github.context.payload = {
pull_request: {
number: 1,
Expand All @@ -188,6 +190,7 @@ describe('mergeLabels, empty config', () => {
it('non empty should join', function () {
const lhs = ['a', 'b', 'c']
const rhs = ['d', 'e', 'f']
github.context.eventName = 'pull_request'
github.context.payload = {
pull_request: {
number: 1,
Expand All @@ -203,6 +206,7 @@ describe('mergeLabels, empty config', () => {
it('should dedupe', function () {
const lhs = ['a', 'b', 'c']
const rhs = ['c', 'b', 'f']
github.context.eventName = 'pull_request'
github.context.payload = {
pull_request: {
number: 1,
Expand Down Expand Up @@ -243,6 +247,7 @@ describe('mergeLabels, sync config', () => {
}

it('lhs empty should join', function () {
github.context.eventName = 'pull_request'
github.context.payload = {
pull_request: {
number: 1,
Expand All @@ -262,6 +267,7 @@ describe('mergeLabels, sync config', () => {
})

it('rhs empty should join', function () {
github.context.eventName = 'pull_request'
github.context.payload = {
pull_request: {
number: 1,
Expand All @@ -277,6 +283,7 @@ describe('mergeLabels, sync config', () => {
})

it('non empty should join', function () {
github.context.eventName = 'pull_request'
github.context.payload = {
pull_request: {
number: 1,
Expand All @@ -292,6 +299,7 @@ describe('mergeLabels, sync config', () => {
})

it('should dedupe', function () {
github.context.eventName = 'pull_request'
github.context.payload = {
pull_request: {
number: 1,
Expand Down
7 changes: 6 additions & 1 deletion dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import files from './matcher/files'
import * as github from '@actions/github'

export function mergeLabels(labels: string[], config: Config): string[] {
const payload =
github.context.payload.pull_request || github.context.payload.issue
const context = github.context
const payload = context.payload.pull_request || context.payload.issue

const currents =
(payload?.labels?.map((label: any) => label.name as string) as string[]) ||
Expand Down
6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as github from '@actions/github'
import {labels, mergeLabels} from './labeler'
import {Config, getConfig} from './config'
import {checks, StatusCheck} from './checks'
import {concat, uniq} from 'lodash'

const githubToken = core.getInput('github-token')
const configPath = core.getInput('config-path', {required: true})
Expand Down Expand Up @@ -36,6 +37,11 @@ async function removeLabels(
labels: string[],
config: Config
): Promise<unknown[]> {
const context = github.context
if (!(context.payload.pull_request || context.payload.issue)) {
return []
}

return Promise.all(
(config.labels || [])
.filter(label => {
Expand Down

0 comments on commit d756102

Please sign in to comment.