Skip to content

Commit

Permalink
Updated the index files support
Browse files Browse the repository at this point in the history
  • Loading branch information
ddevassy committed Apr 13, 2020
1 parent 8a6426c commit 1d88aec
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion fixtures/all.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
projects: ['PROJ']
tickets: ['VC']
check_title: true
check_branch: true
check_commits: true
Expand Down
2 changes: 1 addition & 1 deletion fixtures/branch.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
projects: ['PROJ']
tickets: ['VC']
check_title: false
check_branch: true
ignore_case: true
2 changes: 1 addition & 1 deletion fixtures/commits.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
projects: ['PROJ']
tickets: ['VC']
check_title: false
check_branch: false
check_commits: true
Expand Down
2 changes: 1 addition & 1 deletion fixtures/no-ignore-case.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
projects: ['PROJ']
tickets: ['VC']
check_title: true
check_branch: true
ignore_case: false
2 changes: 1 addition & 1 deletion fixtures/title.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
projects: ['PROJ']
tickets: ['VC']
check_title: true
check_branch: false
ignore_case: true
30 changes: 15 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { Toolkit } = require('actions-toolkit')
const getConfig = require('./utils/config')

const CONFIG_FILENAME = 'pr-lint.yml'
const CONFIG_FILENAME = 'jira_config.yml'

const defaults = {
projects: ['PROJ'],
tickets: ['VC'],
check_title: true,
check_branch: false,
check_commits: false,
ignore_case: false
ignore_case: true
}

Toolkit.run(
Expand All @@ -34,43 +34,43 @@ Toolkit.run(
pull_request.head.ref.toLowerCase() :
pull_request.head.ref

const projects = config.projects.map(project => config.ignore_case ? project.toLowerCase() : project)
const tickets = config.tickets.map(project => config.ignore_case ? project.toLowerCase() : project)
const title_passed = (() => {
if (config.check_title) {
// check the title matches [PROJECT-1234] somewhere
if (!projects.some(project => title.match(createWrappedProjectRegex(project)))) {
tools.log('PR title ' + title + ' does not contain approved project')
// check the title matches [VC-1234] somewhere
if (!tickets.some(project => title.match(createWrappedProjectRegex(project)))) {
tools.log('PR title ' + title + ' does not contain approved Jiras')
return false
}
}
return true
})()

const branch_passed = (() => {
// check the branch matches PROJECT-1234 or PROJECT_1234 somewhere
// check the branch matches VC-1234 or VC_1234 somewhere
if (config.check_branch) {
if (!projects.some(project => head_branch.match(createProjectRegex(project)))) {
tools.log('PR branch ' + head_branch + ' does not contain an approved project')
if (!tickets.some(project => head_branch.match(createProjectRegex(project)))) {
tools.log('PR branch ' + head_branch + ' does not contain an approved Jiras')
return false
}
}
return true
})()

const commits_passed = await (async () => {
// check the branch matches PROJECT-1234 or PROJECT_1234 somewhere
// check the branch matches VC-1234 or VC_1234 somewhere
if (config.check_commits) {
const listCommitsParams = {
owner: repository.owner.login,
repo: repository.name,
pull_number: pull_request.number
}
const commitsInPR = (await tools.github.pulls.listCommits(listCommitsParams)).data
const failedCommits = findFailedCommits(projects, commitsInPR, config.ignore_case);
const failedCommits = findFailedCommits(tickets, commitsInPR, config.ignore_case);

if(failedCommits.length) {
failedCommits.forEach(
failedCommit => tools.log('Commit message \'' + failedCommit + '\' does not contain an approved project')
failedCommit => tools.log('Commit message \'' + failedCommit + '\' does not contain an approved Jiras')
)
return false
}
Expand Down Expand Up @@ -100,9 +100,9 @@ Toolkit.run(
{ event: ['pull_request.opened', 'pull_request.edited', 'pull_request.synchronize'], secrets: ['GITHUB_TOKEN'] }
)

function findFailedCommits(projects, commitsInPR, ignoreCase) {
function findFailedCommits(tickets, commitsInPR, ignoreCase) {
const failedCommits = [];
projects.forEach(project => {
tickets.forEach(project => {
commitsInPR.forEach(commit => {
const commitMessage = ignoreCase ? commit.commit.message.toLowerCase() : commit.commit.message
if (!commitMessage.match(createProjectRegex(project))) {
Expand Down
2 changes: 1 addition & 1 deletion index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { Toolkit } = require('actions-toolkit')

nock.disableNetConnect()

describe('pr-lint-action', () => {
describe('jira-check-action', () => {
let action, tools

// Mock Toolkit.run to define `action` so we can call it
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.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "pr-lint-action",
"name": "jira-check-action",
"private": true,
"main": "index.js",
"scripts": {
"start": "node ./index.js"
},
"dependencies": {
"test": "jest",
"actions-toolkit": "^2.0.0"
},
"devDependencies": {
Expand Down

0 comments on commit 1d88aec

Please sign in to comment.