Package: pr-publisher
OverviewThis is a CLI tool that can list open pull requests and post them somewhere,
mainly Slack. This is useful to help a team stay on top of pull request
reviews.It is configurable, supports multiple publishers, and makes it easy to write
your own publishers.pipinstallpr-publishernote: This is NOT a bot, it is NOT a Slack plugin, and it does NOT support
updating pull requests in any way from the command line.Please report any issues or feature requestson GithubUsageThis installs a script calledpr-publisher,pr-publisher--helpArguments are supplied with CLI options, or environment variables. See the--helpoutput or below for available options.Basic usageThe tool needs a Github personal access token withrepoandread:orgpermissions.[x] repo
[ ] admin:org
    [ ] write:org
    [x] read:org(note: It will try to read branch protection settings to determine the required
checks for the repository. I forget if an additional permission is required
for this)Provide the token either by CLI option, or environment variable.FlagEnv VarExample--github-orgGITHUB_ORGpglbutt--github-tokenGITHUB_TOKEN--github-urlGITHUB_URLhttps://github.<company>.com--include-wip--userspglass,hotpie--approvals-needed2--show-labelsCurrently, the Github organization is required. Open pull requests will be
discovered from all repositories in the org. Optionally, that list can be
filtered down to those owned by specific Github usernames.Github enterprise is supported. Just provide your Github enterprise url with
the--github-url(however, I have not tested 2fa).### Using flagspr-publisher--github-orgmy-org--github-token<token>tableslack### Using environment variablesexportGITHUB_TOKEN=<token>exportGITHUB_ORG=my-org
pr-publisher--userspglass,hotpietableslackBy default, PRs with titles that contain "wip" (case-insensitive) are ignored.
Use the--include-wipflag if you wish to include those.PublishersThe script accepts a list of publisher names. Currently there are two publisherstable: prints the list of pull requests in a table to stdoutslack: posts the list of pull requests to slackEach publisher specified will be run and will publish the list of open pull
requests.### Run the "table" publisherpr-publisher<options>table### Run both the "table" and "slack" publisherspr-publisher<options>tableslackSlack publisherThe slack publisher requires a slack url and token. Currently, the Slack
Jenkins CI integration url is the only tested and known working webhook url.Below is a full list of options,FlagEnv VarExample--slack-tokenSLACK_TOKEN--slack-urlSLACK_URLhttps://<team>.slack.com/services/hooks/jenkins-ci--slack-channelSLACK_CHANNEL#my-team--slack-approved-emojiSLACK_APPROVED_EMOJI:+1:--slack-changes-requested-emojiSLACK_CHANGES_REQUESTED_EMOJI:-1:--slack-status-check-success-emojiSLACK_STATUS_CHECK_SUCCESS_EMOJI:white_check_mark:--slack-status-check-pending-emojiSLACK_STATUS_CHECK_PENDING_EMOJI:grey_question:--slack-status-check-failed-emojiSLACK_STATUS_CHECK_FAILED_EMOJI:x:The slack channel is optional. If not supplied, the slack message is sent to
the channel associated with the token.All emojis default to the empty string and can be plain text strings if you likeThe "approved" and "changes requested" emojis are used to display pull request
approvals.  If your team requires a minimum number of approvals for a pull request,
you should supply the--approvals-neededflag to display how many more approvals
are needed.Custom PublishersThere are two basic steps for a writing your own custom publisher,SubclassBasePublisherwhen creating your publisher classRegister your publisher withMainHere's a basic example. You create your
publisher class, add any cli args you like, and then implement the publish
method."""Example of a custom publisher"""frompr_publisher.publishers.baseimportBasePublisherfrompr_publisher.mainimportMainclassCustomPublisher(BasePublisher):@classmethoddefadd_cli_arguments(cls,parser):# All publisher cli args should be optional. (A user may only care to# run a single publisher, and doesn't want to supply values for the# rest of the publishers)parser.add_argument("--some-chat-url",default=None)def__init__(self,args):super(CustomPublisher,self).__init__(args)ifnotargs.some_chat_url:raiseException("--some-chat-url is required")defpublish(self,publish_entries):forentryinpublish_entries:# Just printing, for the sake of this example.# see pr_publisher.entry.PublishEntry for all available fields.print("{}\n{}".format(entry.pr.title,entry.pr.html_url))defmain():# Register the publisher before we run the programMain.register_publisher("some-chat",CustomPublisher)# Run the programMain().run()if__name__=="__main__":main()You now have your publisher hooked up. You should see the new CLI arguments
show up for thesome-chatpublisher, as well as CLI args for all other
registered publishers (but this is truncated for the example).$pythoncustom_publisher.py-h
...

positionalarguments:{table,slack,some-chat}Listofpublisherstorun

optionalarguments:-h,--helpshowthishelpmessageandexit...--some-chat-urlSOME_CHAT_URLTo run your publisher, specify the publisher name (some-chaton the command
line.$pythoncustom_publisher.py...--some-chat-url'http://chat.example.com'--userspglasssome-chat
Loggingin...
Collectinginfo...
PublishingwithCustomPublisher
Fixingsomebughttps://github.com/pglass/pr-publisher/pull/2
Fixinganotherbughttps://github.com/pglass/pr-publisher/pull/5
Addingsomefeaturehttps://github.com/pglass/pr-publisher/pull/6