forcedotcom / git2gus

A Github application to keep issues in sync with Agile Accelerator
https://lwc-gus-bot.herokuapp.com
BSD 3-Clause "New" or "Revised" License
27 stars 16 forks source link

Support closing work items from PRs that don't have a GH issue #86

Open edmorley opened 4 years ago

edmorley commented 4 years ago

Hi!

There are times when we have a PR open for a repository, that we're tracking via a GUS work item, but for which there isn't a corresponding GitHub issue.

From looking at Git2Gus source it seems that at the moment, the only way to have Git2Gus close the work item automatically when such a PR is merged, would be to:

...which would close the GH issue on merge, and thus in turn the GUS work item.

To save having to create that redundant GitHub work item, it would be great if Git2Gus would listen to the GitHub PR close event, and if the PR description contained the @W-1234@ annotation, then directly close the associated work item.

Now I'm presuming perhaps there are times when one wouldn't want the work item to be closed (eg multiple PRs for a work item, and only the first has merged) - so this should likely only take effect if using say Closes @W-1234@ (or similar)?

To implement I'm presuming the existing integrateWorkItem action could be modified like so...

The GithubEvents.events.PULL_REQUEST_CLOSED event added here: https://github.com/forcedotcom/git2gus/blob/dbe8c53c7bf703d7607ca595ef0a473a843eb3b9/api/actions/integrateWorkItem.js#L19

Then the calculation for the URL to use for related_url adjusted here to work with the PR URL too: https://github.com/forcedotcom/git2gus/blob/dbe8c53c7bf703d7607ca595ef0a473a843eb3b9/api/actions/integrateWorkItem.js#L21-L23

And finally, something like the @W-1234@ annotation logic from here added (with the slight change of needing the "Closes " prefix or similar): https://github.com/forcedotcom/git2gus/blob/dbe8c53c7bf703d7607ca595ef0a473a843eb3b9/api/actions/createChangelist.js#L27-L34

Does that sound reasonable? :-)