From 28116d05fad9489c3ff715fa85d1f9747a8506cd Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Sun, 13 Mar 2022 16:19:15 +0100 Subject: [PATCH 1/6] docs: update AUTOMATIC_CARD_MOVEMENT --- docs/AUTOMATIC_CARD_MOVEMENT.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/AUTOMATIC_CARD_MOVEMENT.md b/docs/AUTOMATIC_CARD_MOVEMENT.md index af032d03..e502db9f 100644 --- a/docs/AUTOMATIC_CARD_MOVEMENT.md +++ b/docs/AUTOMATIC_CARD_MOVEMENT.md @@ -12,8 +12,9 @@ The following table summarizes triggers and the card movements those cause. | Trigger | Action | | :--- | :--- | | Branch with `{issueNumber}-some-description` created | Issue moves to `IN_PROGRESS` column and is assigned to branch author | -| Draft PR referencing issue created | Issue moves to `IN_PROGRESS` column | -| PR is marked as ready-for-review | PR and linked issue move to `IN_REVIEW` column | -| Non-draft PR is created | PR and linked issue move to `IN_REVIEW` column | +| Collaborator PR is created | PR and linked issue move to `IN_REVIEW` or `IN_PROGRESS` (if PR is draft) column | +| Collaborator PR is marked as draft | PR and linked issue move to `IN_PROGRESS` column | +| Collaborator PR is marked as ready-for-review | PR and linked issue move to `IN_REVIEW` column | +| Collaborator PR receives `changes_requested` review | PR moves to `IN_PROGRESS` column | | PR is merged | PR and linked issue move to `DONE` column | | PR is closed unmerged | PR moves to `DONE` column, linked issue stays where it is | From 3fe16b7b8b95e69134d35aaeff8393c44992afad Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Sun, 13 Mar 2022 16:28:13 +0100 Subject: [PATCH 2/6] feat(apps/automatic-dev-flow): auto-assign opened PR --- docs/CONFIG.md | 6 ++++++ packages/app/lib/apps/automatic-dev-flow.js | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/docs/CONFIG.md b/docs/CONFIG.md index 97930e04..542532ee 100644 --- a/docs/CONFIG.md +++ b/docs/CONFIG.md @@ -57,6 +57,12 @@ Several aspects of [wuffle](https://wuffle.dev) are configured via environment v | `DISABLE_BACKGROUND_SYNC` | | | +### Behavior + +| Parameter | Required? | Description | +| :--- | :---: | :--- | +| `AUTO_ASSIGN_PULLS` | | If set, assign newly created collaborator PRs to the PR author | + ### Misc | Parameter | Required? | Description | diff --git a/packages/app/lib/apps/automatic-dev-flow.js b/packages/app/lib/apps/automatic-dev-flow.js index 02a3da05..b1a5ba31 100644 --- a/packages/app/lib/apps/automatic-dev-flow.js +++ b/packages/app/lib/apps/automatic-dev-flow.js @@ -74,16 +74,26 @@ module.exports = function(webhookEvents, githubIssues, columns) { pull_request } = context.payload; + const external = isExternal(pull_request); + const draft = isDraft(pull_request); + const newState = - isExternal(pull_request) ? EXTERNAL_CONTRIBUTION : ( - isDraft(pull_request) ? IN_PROGRESS : IN_REVIEW + external ? EXTERNAL_CONTRIBUTION : ( + draft ? IN_PROGRESS : IN_REVIEW ); const column = columns.getByState(newState); + const author = pull_request.user; + + const newAssignee = ( + process.env.AUTO_ASSIGN_PULLS && !external && + author && author.type === 'User' && author.login + ); + await Promise.all([ - githubIssues.moveIssue(context, pull_request, column), - githubIssues.moveReferencedIssues(context, pull_request, column) + githubIssues.moveIssue(context, pull_request, column, newAssignee), + githubIssues.moveReferencedIssues(context, pull_request, column, newAssignee) ]); }); From 8880076ccdf63cbd320ced3c9c9cf4932eb7d9b3 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Sun, 13 Mar 2022 16:53:53 +0100 Subject: [PATCH 3/6] fix: correct avatar sizing --- packages/board/src/CollaboratorLinks.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/board/src/CollaboratorLinks.svelte b/packages/board/src/CollaboratorLinks.svelte index a73dafa7..bdefb62c 100644 --- a/packages/board/src/CollaboratorLinks.svelte +++ b/packages/board/src/CollaboratorLinks.svelte @@ -102,7 +102,7 @@ margin: 0; font-size: 14px; position: relative; - display: inline-block; + display: flex; text-align: center; border-radius: 2px; From 6f65ac23ddf2625f5fb4786472f7256709fbffb2 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Sun, 13 Mar 2022 17:01:00 +0100 Subject: [PATCH 4/6] fix(events-sync): react to `pull_request.converted_to_draft` --- packages/app/lib/apps/events-sync.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/app/lib/apps/events-sync.js b/packages/app/lib/apps/events-sync.js index ddca98e9..cb77472c 100644 --- a/packages/app/lib/apps/events-sync.js +++ b/packages/app/lib/apps/events-sync.js @@ -101,6 +101,7 @@ function EventsSync(webhookEvents, store, logger) { 'pull_request.unlabeled', 'pull_request.edited', 'pull_request.ready_for_review', + 'pull_request.converted_to_draft', 'pull_request.assigned', 'pull_request.unassigned', 'pull_request.synchronize', From 676e2fa3d7f20ef79232cf0c5f416e91341c89db Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Thu, 4 Nov 2021 09:42:17 +0100 Subject: [PATCH 5/6] WIP(app): convert to draft and back again --- .../lib/apps/github-issues/GithubIssues.js | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/packages/app/lib/apps/github-issues/GithubIssues.js b/packages/app/lib/apps/github-issues/GithubIssues.js index 5b6958e5..3e658398 100644 --- a/packages/app/lib/apps/github-issues/GithubIssues.js +++ b/packages/app/lib/apps/github-issues/GithubIssues.js @@ -7,6 +7,8 @@ const { CLOSES } = linkTypes; +const gql = require('fake-tag'); + /** * @constructor @@ -76,6 +78,20 @@ function GithubIssues(logger, config, columns) { }; } + function getDraftUpdate(issue, newColumn) { + if ('draft' in issue) { + const draft = columns.getByState('IN_PROGRESS') === newColumn; + + if (draft !== issue.draft) { + return { + draft + }; + } + } + + return {}; + } + function findIssue(context, issue_number) { const params = context.repo({ issue_number }); @@ -131,12 +147,51 @@ function GithubIssues(logger, config, columns) { })); } + function updateDraftState(context, pullRequest, draft) { + + const convertToDraftQuery = gql` + mutation ConvertToDraft($pull_id: ID!) { + convertPullRequestToDraft(input: { pullRequestId: $pull_id }) { + pullRequest { + updatedAt + } + } + } + `; + + const markReadyForReviewQuery = gql` + mutation MarkReadyForReview($pull_id: ID!) { + markPullRequestReadyForReview(input: { pullRequestId: $pull_id }) { + pullRequest { + updatedAt + } + } + } + `; + + const ctx = context.repo({ + issue_number: pullRequest.number, + draft + }); + + log.info(ctx, 'set draft'); + + return context.octokit.graphql( + draft ? convertToDraftQuery : markReadyForReviewQuery, + { + pull_id: pullRequest.pull_request_node_id + } + ).catch(error => log.error(error, 'failed to set draft', ctx)); + } + function moveIssue(context, issue, newColumn, newAssignee) { const { number: issue_number } = issue; + const draftUpdate = getDraftUpdate(issue, newColumn); + const update = { ...getAssigneeUpdate(issue, newAssignee), ...getStateUpdate(issue, newColumn) @@ -163,6 +218,14 @@ function GithubIssues(logger, config, columns) { ); } + if (hasKeys(draftUpdate)) { + const { draft } = draftUpdate; + + invocations.push( + updateDraftState(context, issue, draft) + ); + } + if (hasKeys(update)) { const params = context.repo({ From 4c44e85d9dacd0c787edf25a535e76f94c96571d Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Sat, 13 Nov 2021 14:58:52 +0100 Subject: [PATCH 6/6] test: verify convert-to-draft and back again TOKEN=GITHUB_ACCESS_TOKEN npx lerna exec --scope=wuffle node test.js --- packages/app/test.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 packages/app/test.js diff --git a/packages/app/test.js b/packages/app/test.js new file mode 100644 index 00000000..ccd0050c --- /dev/null +++ b/packages/app/test.js @@ -0,0 +1,35 @@ +const gql = require('fake-tag'); + +const { graphql } = require('@octokit/graphql'); + +const authenticatedGraphql = graphql.defaults({ + headers: { + authorization: `token ${process.env.TOKEN}` + } +}); + +const convertToDraftQuery = gql` + mutation ConvertToDraft($pull_id: ID!) { + convertPullRequestToDraft(input: { pullRequestId: $pull_id }) { + pullRequest { + updatedAt + } + } + } +`; + +const markReadyForReviewQuery = gql` + mutation MarkReadyForReview($pull_id: ID!) { + markPullRequestReadyForReview(input: { pullRequestId: $pull_id }) { + pullRequest { + updatedAt + } + } + } +`; + +authenticatedGraphql(markReadyForReviewQuery, {"pull_id": "MDExOlB1bGxSZXF1ZXN0MzI3NTkzNTc2" }).then(result => { + console.log(result); +}).catch(err => { + console.error(err); +}); \ No newline at end of file