Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Dev #93

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: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

.env
coverage/
coverage/
node_modules/
12 changes: 12 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Ignore artifacts:
build
public

# dev
yarn.lock
package-lock.json
coverage
.vercel
.node_modules
CHANGELOG.md
*.log
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"useTabs": false,
"trailingComma": "es5",
"printWidth": 120
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Philip Schatz
Copyright (c) 2021 Mark Lyck

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
24 changes: 15 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
{
"name": "project-bot",
"version": "2.0.5",
"description": "Add new Issues and PullRequests to a GitHub Project Board",
"name": "project-bot-next",
"version": "1.0.1",
"description": "Automate Issues and PullRequests to a GitHub Project Board",
"main": "src/index.js",
"scripts": {
"start": "probot run ./src/index.js",
"lint": "standard --fix",
"test": "jest",
"posttest": "standard",
"test:fix": "jest --updateSnapshot && standard --fix"
"test:fix": "jest --updateSnapshot && standard --fix",
"gc": "pretty-quick --staged && gitmoji -c",
"gca": "git add . && yarn gc",
"gcap": "yarn gca && git push"
},
"repository": {
"type": "git",
"url": "git+https://github.com/philschatz/project-bot.git"
"url": "git+https://github.com/MarkLyck/project-bot.git"
},
"author": "Philip Schatz",
"author": "Mark Lyck",
"bugs": {
"url": "https://github.com/philschatz/project-bot/issues"
"url": "https://github.com/MarkLyck/project-bot/issues"
},
"homepage": "https://github.com/philschatz/project-bot#readme",
"homepage": "https://github.com/MarkLyck/project-bot#readme",
"now": {
"alias": "project-bot",
"alias": "project-bot-next",
"dotenv": ".env"
},
"jest": {
Expand All @@ -32,8 +35,11 @@
"probot": "^9.2.20"
},
"devDependencies": {
"gitmoji-cli": "3.3.0",
"jest": "^24.8.0",
"nock": "^10.0.6",
"prettier": "^2.2.1",
"pretty-quick": "3.1.0",
"smee-client": "^1.1.0",
"standard": "^13.1.0"
}
Expand Down
82 changes: 58 additions & 24 deletions src/commands.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
function ALWAYS_TRUE () { return true }
function ALWAYS_TRUE() {
return true
}

module.exports = [
{ ruleName: 'edited_issue', webhookName: 'issues.edited', ruleMatcher: ALWAYS_TRUE },
{ ruleName: 'demilestoned_issue', webhookName: 'issues.demilestoned', ruleMatcher: ALWAYS_TRUE },
{ ruleName: 'milestoned_issue', webhookName: 'issues.milestoned', ruleMatcher: ALWAYS_TRUE },
{ ruleName: 'reopened_pullrequest', webhookName: 'pull_request.reopened', ruleMatcher: ALWAYS_TRUE },
{ ruleName: 'reopened_issue', webhookName: 'issues.reopened', ruleMatcher: ALWAYS_TRUE },
{ ruleName: 'closed_issue', webhookName: 'issues.closed', ruleMatcher: ALWAYS_TRUE },
{ ruleName: 'added_reviewer', webhookName: 'pull_request.review_requested', ruleMatcher: ALWAYS_TRUE }, // See https://developer.github.com/v3/activity/events/types/#pullrequestevent to get the reviewer
{
ruleName: 'edited_issue',
webhookName: 'issues.edited',
ruleMatcher: ALWAYS_TRUE,
},
{
ruleName: 'demilestoned_issue',
webhookName: 'issues.demilestoned',
ruleMatcher: ALWAYS_TRUE,
},
{
ruleName: 'milestoned_issue',
webhookName: 'issues.milestoned',
ruleMatcher: ALWAYS_TRUE,
},
{
ruleName: 'reopened_pullrequest',
webhookName: 'pull_request.reopened',
ruleMatcher: ALWAYS_TRUE,
},
{
ruleName: 'reopened_issue',
webhookName: 'issues.reopened',
ruleMatcher: ALWAYS_TRUE,
},
{
ruleName: 'closed_issue',
webhookName: 'issues.closed',
ruleMatcher: ALWAYS_TRUE,
},
{
ruleName: 'added_reviewer',
webhookName: 'pull_request.review_requested',
ruleMatcher: ALWAYS_TRUE,
}, // See https://developer.github.com/v3/activity/events/types/#pullrequestevent to get the reviewer
{
createsACard: true,
ruleName: 'new_issue',
Expand All @@ -20,7 +50,7 @@ module.exports = [
} else {
return true
}
}
},
},
{
createsACard: true,
Expand All @@ -35,23 +65,23 @@ module.exports = [
} else {
return true
}
}
},
},
{
ruleName: 'merged_pullrequest',
webhookName: 'pull_request.closed',
ruleMatcher: async function (logger, context, ruleArgs) {
// see https://developer.github.com/v3/activity/events/types/#pullrequestevent
return !!context.payload.pull_request.merged
}
},
},
{
ruleName: 'closed_pullrequest',
webhookName: 'pull_request.closed',
ruleMatcher: async function (logger, context, ruleArgs) {
// see https://developer.github.com/v3/activity/events/types/#pullrequestevent
return !context.payload.pull_request.merged
}
},
},
{
ruleName: 'assigned_to_issue',
Expand All @@ -62,65 +92,65 @@ module.exports = [
} else {
logger.error(`assigned_to.issue requires a username but it is missing`)
}
}
},
},
{
ruleName: 'assigned_issue',
webhookName: 'issues.assigned',
ruleMatcher: async function (logger, context, ruleArgs) {
return context.payload.issue.assignees.length === 1
}
},
},
{
ruleName: 'unassigned_issue',
webhookName: 'issues.unassigned',
ruleMatcher: async function (logger, context, ruleArgs) {
return context.payload.issue.assignees.length === 0
}
},
},
{
ruleName: 'assigned_pullrequest',
webhookName: 'pull_request.assigned',
ruleMatcher: async function (logger, context, ruleArgs) {
return context.payload.pull_request.assignees.length === 1
}
},
},
{
ruleName: 'unassigned_pullrequest',
webhookName: 'pull_request.unassigned',
ruleMatcher: async function (logger, context, ruleArgs) {
return context.payload.pull_request.assignees.length === 0
}
},
},
{
ruleName: 'added_label',
webhookName: 'issues.labeled',
ruleMatcher: async function (logger, context, ruleArgs) {
// labels may be defined by a label or an id (for more persistence)
return context.payload.label.name === ruleArgs[0] || context.payload.label.id === ruleArgs[0]
}
},
},
{
ruleName: 'added_label',
webhookName: 'pull_request.labeled',
ruleMatcher: async function (logger, context, ruleArgs) {
// labels may be defined by a label or an id (for more persistence)
return context.payload.label.name === ruleArgs[0] || context.payload.label.id === ruleArgs[0]
}
},
},
{
ruleName: 'removed_label',
webhookName: 'issues.unlabeled',
ruleMatcher: async function (logger, context, ruleArgs) {
return context.payload.label.name === ruleArgs[0] || context.payload.label.id === ruleArgs[0]
}
},
},
{
ruleName: 'removed_label',
webhookName: 'pull_request.unlabeled',
ruleMatcher: async function (logger, context, ruleArgs) {
return context.payload.label.name === ruleArgs[0] || context.payload.label.id === ruleArgs[0]
}
},
},
{
ruleName: 'accepted_pullrequest',
Expand All @@ -129,7 +159,11 @@ module.exports = [
// See https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent
// Check if there are any Pending or Rejected reviews and ensure there is at least one Accepted one
const issue = context.issue()
const { data: reviews } = await context.github.pullRequests.listReviews({ owner: issue.owner, repo: issue.repo, pull_number: issue.number })
const { data: reviews } = await context.github.pullRequests.listReviews({
owner: issue.owner,
repo: issue.repo,
pull_number: issue.number,
})
// Check that there is at least one Accepted
const hasAccepted = reviews.filter((review) => review.state === 'APPROVED').length >= 1
const hasRejections = reviews.filter((review) => review.state === 'REQUEST_CHANGES').length >= 1
Expand All @@ -139,6 +173,6 @@ module.exports = [
} else {
return false
}
}
}
},
},
]
11 changes: 7 additions & 4 deletions src/extract-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const commonmarkParser = new commonmark.Parser()
// - `added_label` **wontfix**
// - `new_pullrequest` **foo-bar** **test**
// ```
function parseMarkdown (card) {
function parseMarkdown(card) {
if (!card.note) {
return [] // no Rules
}
Expand All @@ -36,7 +36,10 @@ function parseMarkdown (card) {
}
// Try splitting up the text (backwards-compatibility)
if (args.length === 0 && node.next && node.next.literal) {
args = node.next.literal.trim().split(' ').map((arg) => arg.trim())
args = node.next.literal
.trim()
.split(' ')
.map((arg) => arg.trim())
}
parsedRules.push({ ruleName: node.literal, ruleArgs: args })
}
Expand All @@ -46,7 +49,7 @@ function parseMarkdown (card) {
}

// For parse out all the Automation Rules from Cards in a Project
module.exports = function extractAutomationRules (projects) {
module.exports = function extractAutomationRules(projects) {
const automationRules = []

// Use a Map to deduplicate because .firstCards and .lastCards could be the same Card
Expand All @@ -68,7 +71,7 @@ module.exports = function extractAutomationRules (projects) {
automationRules.push({
column,
ruleName: r.ruleName,
ruleArgs: r.ruleArgs
ruleArgs: r.ruleArgs,
})
})
})
Expand Down
Loading