Git Product home page Git Product logo

jira-github-pr-check's Introduction

Jira GitHub PR Checker

A small webhook service that forces GitHub pull requests to have a valid, accepted Jira ticket in the title.

This service can be run on its own, and it is also designed with the capability to run as a GCP Cloud Function.

Quick Start

To run as a server locally on the port given in the environment variable:

$ node bin/server.js

If running as a GCP Cloud Function, set "app" as the "Function to execute" in the Cloud Functions settings page. The server.js file will not be used; GCP will import the library function from app.js directly.

The file "cloudbuild.yaml" is available in case you want to set up an automatic deployment based on a git repository push trigger.

PR Flags

The following "variables" can be set in the pull request body to change the behavior of the checker.

// Allow commits with mixed issue tags
DISABLE_JIRA_ISSUE_MATCH=true

// Allow multiple commits in the same PR
ALLOW_MANY_COMMITS=true

Environment

The following environment variables are expected. If a .env file is present, they will be read from there:

# Hostname of your Jira instance.
JIRA_URL=unicode-org.atlassian.net

# Authentication for your Jira instance.
# If not present, authentication for Jira will not be used.
#
# JIRA_USERNAME should be an *email address*, and JIRA_PASSWORD should be an
# API token generated at https://id.atlassian.com/manage/api-tokens
[email protected]
JIRA_PASSWORD=bar

# URL prefix used for hyperlinks.
URL_PREFIX=http://localhost:3000

# Optional URL to your contribution guidelines; produces a link on the info page:
INSTRUCTIONS_URL=http://site.icu-project.org/processes/contribute

# Port to use when serving.
# Not required when used in Google Cloud Functions.
PORT=3000

# Optional GitHub secret; save the secret here and in the "secret" field when configuring the GitHub webhook:
GITHUB_WEBHOOK_SECRET=xxxxxxxxxx

# Committer name and email, used for squash commits.
# By default, use author as committer.
COMMITTER_NAME=Squash Bot
[email protected]

# Secret for the cookie session, used to store the user's GitHub access token in a cookie.
COOKIE_SECRET=xxxxxxxxxx

# Optional list of repos to disable status updates (only enable force-push checking)
DO_NOT_TOUCH_REPOS=org/repo1,org/repo2

# GitHub permissions:

# Option 1: Personal Access Token; easiest and useful for testing.
# Create one of these from https://github.com/settings/tokens
GITHUB_TOKEN=xxxxxxxxxx

# Option 2: GitHub App
# Create one of these from https://github.com/settings/apps
# If using an organization account, you can create the GitHub app there.
#
# GitHub App Permissions and Webhooks:
#  - Pull requests: Access: Read-only
#  - Commit statuses: Access: Read & write
#  - Subscribe to events: Pull request
#
# Find the ID (an integer) under "About" after you create the GitHub app.
# Find the Installation ID (another integer) in the URL after you add the app with permissions to your repositories.
GITHUB_APP_ID=12345
GITHUB_APP_INSTALLATION_ID=123456

# GitHub Apps use private keys for authentication to GitHub APIs.
# Choose 2a or 2b for how to specify your private key file, generated near the bottom of the GitHub app main information screen.

# 2a: PEM file path, relative to the repository root.
# The directory "keys" can be created; it is ignored by source control.
GITHUB_APP_PEM_FILE=keys/xyz.private-key.pem

# 2b: PEM as an environment variable blob.
# Encode the PEM file as base64 and save it in this environment variable.
GITHUB_APP_PEM_BLOB=LS0tLS1...

# In addition, you should make an OAuth App that can get user-by-user permissions to perform squash commits.
# Create one of these from https://github.com/settings/developers
# If using an organization account, you can create the OAuth app there.
GITHUB_OAUTH_CLIENT_ID=xxxxxxxxxx
GITHUB_OAUTH_CLIENT_SECRET=xxxxxxxxxx

Copyright & Licenses

Copyright © 2018-2024 Unicode, Inc. Unicode and the Unicode Logo are registered trademarks of Unicode, Inc. in the United States and other countries.

The project is released under LICENSE.

A CLA is required to contribute to this project - please refer to the CONTRIBUTING.md file (or start a Pull Request) for more information.

jira-github-pr-check's People

Contributors

dependabot[bot] avatar sffc avatar srl295 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jira-github-pr-check's Issues

travis

add a basic travis that verifies that npm ci and the linter are working

Should not modify closed PRs

If the state of a ticket changes after the PR is merged, the check status should continue to reflect the state at the time of merging. To fix this, the checker should not be able to modify PRs that have been merged or closed.

Dockerize

add a simple docker file to simplify deployment

slashes confuse the checker?

over on unicode-org/cldr#1085 the following text failed both PR title and Commit title validation:

  • CLDR-14395 /api/auth endpoints

with "PR must begin with a Jira ticket ID" etc.

Changing to CLDR-14395 API for … fixed it. Something with slashes?

P1 Commit / PR validation: be more helpful

see also #30

jira-ticket — Commit message for 9d1c3e3 fails validation

… is not very helpful as to what should be present, especially for a message that does contain CLDR-15180 somewhere in it.

Proposal:

  • If a valid JIRA id (even on a loose match - match Cldr:15180 or similar) then suggest as follows:
Bad Commit message for 9d1c3e3:  'CLDR-15180 Describe the change here'

Describe the change here could be a static string, or could be calculated starting with the first alpha character.

That way if we get a message such as Cldr-15180 - /bin/sh was not found then it will instead say: CLDR-15180 bin/sh was not found (Extraneous: ' - /') - and show what part was causing the validation failure.

Update JIRA ticket with status on merge

@sffc this is somewhat of a question.

  • Does the pr-check get notified when a PR is merged?

Context: https://unicode-org.atlassian.net/browse/CLDR-15400

There's sometimes confusion when a PR or commit mentions a JIRA ticket but isn't targetted at that ticket. xrefs are super helpful, but can add noise. (I filed this ticket to try to avoid needing some kind of policy that restricts mentioning other tickets.)

Jira's "developer" field isn't really a field, you can't really search for "Tickets that have commits" and even if you could, you don't know if the ticket was really fixed by the PR or just mentioned by it.

If pr-check gets notified on merge, then it could actually update a Jira field, something like "mergedIn".

  • For branch maint/maint-43 it could definitely add maint-43 to mergedIn.
  • For branch main it could add main to mergedIn

More advanced:

  • We could somehow use the current version logic to actually use the "targeted release version" for that branch for the mergedIn field.
  • mergedIn should be a list, not a singleton, because of cherry picks.

Add squashing tool

The tool should have a button from the PR error page that fixes up the commit messages for you and overwrites the branch with a squash commit, where the commit message is the PR title. The tool can ask the user for OAuth write permission to their repository and perform the fix in one or two clicks.

@srl295

P3 PR title: automatically fix

See #37 referring to #36

If the PR title is something like Cldr-1234 - Something Here could the checker actually modify the PR title and change it to CLDR-1234 Something Here automatically?

Add link to bot page from "single-commit" status

When the single-commit status fails, I've heard multiple times from multiple users that they don't realize that they can scroll down to the "jira-ticket" status to get to the details page that has the Squash Branch button. It might make it more discoverable if we add a link to the same page as "jira-ticket" from the "single-commit" status.

Require PR owner?

Should the bot also require a PR owner?

Upside is that ownership shows up earlier in lists of PRs.

Downside is that community contributions, that might otherwise pass tests, will show with an X as broken when they might be otherwise OK.

P1 Auto-approve PRs that are force-pushed

Context: https://github.community/t5/How-to-use-Git-and-GitHub/Auto-approve-force-pushes-if-PR-was-already-approved/m-p/15029/thread-id/4672

The checker tool should be able to detect when the only change to a PR was a force-push to squash, edit commit message, etc., and it should automatically re-approve the PR.

If not auto-approve, the bot should at least leave a comment saying that the code is the same, so that the human reviewer doesn't have to take that on faith.

@srl295

Should you use a secret for inbound?

I don't know what 'creating a status is', but because there's a github credential, it might be good to use a secret (there's a field for it) in connecting to the webhook.

Bot should ignore draft pull requests

When a PR is in early development, the bot can be noisy. Given that the bot's primary purpose is to help with code reviews, there should be an option (or perhaps make it the default behavior) to suppress notifications if a PR is in Draft state.

CC @Manishearth

Improve handling of multiple authors

Currently if two authors push to a branch, it looks like jira-github-pr-check squashes to a commit attributed to the last author. A small fix by a reviewer can thus result in the reviewer getting full blame - thus discouraging direct fixes.

Options:

  • refusing to squash when there's more than one author?
  • using the first author, not the last?
  • or at least warning very clearly when there's more than one?
  • some way of explicitly choosing which author?
  • (only squashing successive commits by the same author?) <- not recommended, when the same author might also commit with different email addresses. And the end-result isn't a single commit.

I like the first option above: I think it's reasonable to just let people squash manually when there's more than one author.

please rename the default branch of this repo from "master" to "main"

I believe that this is now the last of the unicode-org repos which is still using "master". (Except for archived repos.)
According to the notes on our tracking spreadsheet, this was tried before and "changed back to master due to GCP bug".
Could someone please look at what bug that was and whether we can get past it now?

@srl295 @sffc

Add support for non-public Jira tickets

Right now, the check is wired up for only public tickets; there is no authentication to Jira. This means that tickets not viewable publicly, such as those with "sensitive" security level. It's unclear whether this is a bug or a feature.

@markusicu @srl295

Suggest certain PR types

When merging from a maint branch to master, the tool should remind the developer not to use the rebase-merge button. There does not appear to be a way for the tool to prevent the use of the rebase merge button, but at least it could leave a status that reminds the developer and makes the button non-green.

unicode-org/icu#539

doc: scope

# Option 1: Personal Access Token; easiest and useful for testing.
# Create one of these from https://github.com/settings/tokens
GITHUB_TOKEN=xxxxxxxxxx

I'm guessing repo:status scope is what's needed?

make exceptions human readable

a3de9a3 supports DISABLE_JIRA_ISSUE_MATCH=true

Instead, how about something like this:

DisableJiraIssueMatch: because this is a merge from the maint branch

In other words, a special token at the beginning, and then a required description.

Can text follow DISABLE_JIRA_ISSUE_MATCH=true? Then:

DISABLE_JIRA_ISSUE_MATCH=true: because this is a merge from the maint branch

would work. but a human readable description is important.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.