Skip to content

Latest commit

 

History

History
249 lines (179 loc) · 22.2 KB

README.md

File metadata and controls

249 lines (179 loc) · 22.2 KB

Pull Request Stats

CI

This is a fork of pull-request-stats Github action to print relevant stats about Pull Request reviewers adapted to run as drone.io plugin.

The objective of this plugin is to:

  • Reduce the time taken to review the pull requests.
  • Encourage quality on reviews.
  • Help deciding which people to assign as reviewers.

Running this plugin will add a section at the bottom of your pull requests description:

Each reviewer has a link pointing to their historical behavior of each reviewer:

Or integrate this action with Slack:

Privacy

  • No repository data is collected, stored or distributed by this GitHub action. This action is state-less.
  • Charts data is send over the URL, and never stored or transmitted anywhere else.
  • Minimal data is send to Mixpanel in order to improve this action. However, you can opt-out using telemetry option.

Usage

Just add this action to one of your workflow files:

      - name: Run pull request stats
        uses: KazanExpress/pull-request-stats@master

Action inputs

The possible inputs for this action are:

Parameter Description Default
token A Personal Access Token with repo permissions. Required to calculate stats for an organization or multiple repos. GITHUB_TOKEN
repositories A comma separated list of github repositories to calculate the stats, eg. username/repo1,username/repo2. When specifying other repo(s) it is mandatory to pass a Personal Access Token in the token parameter. Current repository
organization If you prefer, you may specify the name of your organization to calculate the stats across all of its repos. When specifying an organization it is mandatory to pass a Personal Access Token in the token parameter. null
period The length of the period used to calculate the stats, expressed in days. 30
limit The maximum number of rows to display in the table. A value of 0 means unlimited. 0
charts Whether to add a chart to the start or not. Possible values: true or false. false
disable-links If true, removes the links to the detailed charts. Possible values: true or false. false
sort-by The column used to sort the data. Possible values: REVIEWS, TIME, COMMENTS. REVIEWS
publish-as Where to publish the results. Possible values: as a COMMENT, on the pull request DESCRIPTION. COMMENT
telemetry Indicates if the action is allowed to send monitoring data to the developer. This data is minimal and helps me improve this action. This option is a premium feature reserved for sponsors. true
slack-webhook 🔥 New. A Slack webhook URL to post resulting stats. This option is a premium feature reserved for sponsors. null
slack-channel The Slack channel where stats will be posted. Include the # character (eg. #mychannel). Required when a slack-webhook is configured. null
webhook 🔥 New. A webhook URL to send the resulting stats as JSON (integrate with Zapier, IFTTT...). See full documentation here. null

Examples

Minimal config

Add this to the file .drone.yml in your repo:

kind: pipeline
name: pr-stats
type: docker

trigger:
  event:
    - pull_request
  branch:
    - master

steps:
  - name: pull request stats
    image: ghcr.io/kazanexpress/drone-pull-request-stats
    settings:
      github_token:
        from_secret: github_token
      period: '30'
      limit: '100'
      sort_by: 'COMMENTS'
      charts: 'true'

This config will:

  • Calculate the reviewer stats for the current repo in the lasts 30 days
  • Add links to the historial data
  • Sort results by the "total reviews" column by default

and print a table like this:

User Total reviews Median time to review Total comments
jartmez 37 22m 13
manuelmhtr 35 48m 96
ernestognw 25 1h 27m 63
javierbyte 12 30m 0
Phaze1D 4 34m 1

Visual config

Add this to the file .github/workflows/stats.yml:

kind: pipeline
name: pr-stats
type: docker

trigger:
  event:
    - pull_request
  branch:
    - master

steps:
  - name: pull request stats
    image: ghcr.io/kazanexpress/drone-pull-request-stats
    settings:
      github_token:
        from_secret: github_token
      limit: '100'
      sort_by: 'COMMENTS'
      charts: 'true'
      organization: 'piedpiper'
      period: '7'
      disable_links: 'true'

This config will:

  • Calculate the reviewer stats for all the repos in the "piedpiper" organization in the lasts 7 days
  • Display charts for the metrics
  • Remove the links to detailed charts
  • Sort results by the "comments" column

and print a table like this:

User Total comments Total reviews Median time to review
manuelmhtr
🥇
12
▀▀▀▀▀▀▀▀
8
▀▀▀▀
53m
jartmez
🥈
3
▀▀
4
▀▀
58m
JohanAlvarado
🥉
1
2
1d 16h 18m
▀▀▀▀▀▀
Estebes10
1
1
19m
ernestognw
0
2
2h 15m
Phaze1D
0
3
1h 28m
javierbyte
0
1
21h 24m
▀▀▀

Stats

The stats are calculated as following:

  • Time to review: It is the time taken by a reviewer from the Pull Request publication or the last Commit push (whatever happens last) to the first time the pull request is reviewed.
  • Time to review: It is the median of the times to review of all Pull Requests reviewed by a person in the period.
  • Total reviews: It is the count of all Pull Requests reviewed by a person in the period.
  • Total comments: It is the count of all the comments while reviewing other user's Pull Requests in the period (comments in own PRs don't count).

Slack integration

To configure the Slack, integration:

  1. Create a webhook in your workspace (you must be a Slack admin). It should look like this: https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX. Check out this tutorial if you have questions on how to get the webhook URL.
  2. Set the slack-webhook (from previous step) and slack-channel (don't forget to include the # character) parameters in this action.
  3. Ready to go!

Since it may be quite annoying to receive a Slack notification everytime someone creates a pull request, it is recommended to configure this action to be executed every while using the schedule trigger. For example, every monday at 9am UTC:

kind: pipeline
name: pr-stats
type: docker

trigger:
  event:
    - cron

steps:
  - name: pull request stats
    image: ghcr.io/kazanexpress/drone-pull-request-stats
    settings:
      github_token:
        from_secret: github_token
      slack_channel: '#mystatschannel'
      slack_webhook: 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX'
      # slack-webhook:
        # from-secret: slack_webhook You may want to store this value as a secret.

Troubleshooting

The action is printing an empty table.
  1. Make sure the repositories have pull request reviews during the configured period.
  2. When specifying repositories or organization paramaters, a Personal Access Token is required in the token parameter.
  3. If providing a Personal Access Token, make sure it has the repo permission for the projects you want.
I'm a sponsor but still getting the error "...is a premium feature, available to sponsors".
  1. Check the sponsorship comes from the account that owns the configured repos (usually an organization).
  2. Make sure the sponsorship is configured as public, otherwhise the action cannot access the sponsorship information. If you prefer to keep it private, please reach me out to make it works for you that way 😉.

Premium features ✨

This action offers some premium features only for sponsors:

  • Disabling telemetry.
  • Slack integration.
  • Comming soon: Microsoft teams and discord integrations.

No minimum amount is required for now. In the future, a minimum monthly sponsorship will be inforced to access premium features.

Suggested sponsorship is $20 usd / month. Thanks for your support! 💙

Used by

Used by hundreds of successful teams:


Sixt

Lululemon

Delivery H

JOKR

Qatalog

LOOP

Hatch

Zenfi

Trivago

Discovery

Addition

Fauna

CDC

Wecasa

Bolt

Republic

Author

@manuelmhtr
🇲🇽 Guadalajara, MX

Help

This project is maintained by a single person, considering supporting the project by:

License

MIT