Skip to content

Commit

Permalink
Merge pull request #1 from yogevbd/test
Browse files Browse the repository at this point in the history
v1.0.0
  • Loading branch information
yogevbd authored Sep 20, 2019
2 parents aa11fd8 + f9af700 commit 35fe12b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
12 changes: 8 additions & 4 deletions .github/main.workflow
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
workflow "Verify labels" {
on = "push"
resolves = "Verify"
on = "pull_request"
resolves = "VerifyLabels"
}

action "Verify" {
uses = "yogevbd/enforce-label-action@master"
action "VerifyLabels" {
uses = "yogevbd/enforce-label-action@test"
secrets = ["GITHUB_TOKEN"]
env = {
VALID_LABELS = "bug,enhancement,feature"
}
}
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Enforce PR label

Enforce choosing label before merging PR. Usefull for generating automatic changelog and release notes with `github-release-notes`

## Example usage
Create `.github/main.workflow` containing:

```
workflow "Verify labels" {
on = "pull_request"
resolves = "VerifyLabels"
}
action "VerifyLabels" {
uses = "yogevbd/enforce-label-action@master"
secrets = ["GITHUB_TOKEN"]
env = {
VALID_LABELS = "bug,enhancement,feature"
}
}
```
22 changes: 15 additions & 7 deletions lib/run.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const request = require('./request')

const { GITHUB_SHA, GITHUB_EVENT_PATH, GITHUB_TOKEN, GITHUB_WORKSPACE } = process.env
const { GITHUB_SHA, GITHUB_EVENT_PATH, GITHUB_TOKEN } = process.env
const event = require(GITHUB_EVENT_PATH)
const { repository } = event
const { repository, pull_request } = event
const labels = pull_request.labels.map((l) => l.name);
const validLabels = process.env.VALID_LABELS.split(',');

const {
owner: { login: owner }
} = repository
Expand All @@ -16,7 +19,7 @@ const headers = {
Authorization: `Bearer ${GITHUB_TOKEN}`,
'User-Agent': 'enforce-label-action'
}

async function createCheck() {
const body = {
name: checkName,
Expand All @@ -35,11 +38,16 @@ async function createCheck() {
}

function verifyLabel() {
let success = 0;
if (labels.some(l => validLabels.includes(l))) {
success = 1;
}

return {
conclusion: 'success',
conclusion: success == 1 ? 'success' : 'failure',
output: {
title: 'checkName',
summary: `${'errorCount'} error(s), ${'warningCount'} warning(s) found`
title: `Please add at least one valid label - ${validLabels}`,
summary: ``
}
}
}
Expand Down Expand Up @@ -73,9 +81,9 @@ async function run() {
const id = await createCheck()
try {
const { conclusion, output } = verifyLabel()
console.log(output.summary)
await updateCheck(id, conclusion, output)
if (conclusion === 'failure') {
console.log(conclusion)
process.exit(78)
}
} catch (err) {
Expand Down

0 comments on commit 35fe12b

Please sign in to comment.