Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wesleyscholl/github-jira-pr-script
Automating pull request creation with Jira info from the command line.
https://github.com/wesleyscholl/github-jira-pr-script
Last synced: 3 days ago
JSON representation
Automating pull request creation with Jira info from the command line.
- Host: GitHub
- URL: https://github.com/wesleyscholl/github-jira-pr-script
- Owner: wesleyscholl
- License: mit
- Created: 2023-10-24T04:51:54.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-08T22:12:30.000Z (2 months ago)
- Last Synced: 2024-09-09T16:52:22.344Z (2 months ago)
- Language: Shell
- Size: 49.8 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# github-jira-pr-script - Automating pull request creation with Jira projects from the command line 👨🏻💻➡️🌐✅
Manually creating a GitHub pull request is a time-consuming task. Save time using this shell script.
> [!NOTE]
> **There are now two versions of this script:**
>
> - `pr-script.sh` pulls JIRA ticket information and populates a pre-existing pull request template, PR summary provided by Gemini AI.
> - `public-pr-script.sh` creates a new pull request using the branch name, `git diff`, and git commits with hashes, PR summary provided by Gemini AI. I created this version for general use, not specific to Jira.## Table of Contents
* [What this script automates](#what-this-script-automates)
* [Requirements](#requirements)
* [Mac Installation](#mac-installation)
* [Windows Installation](#windows-installation)
* [Before submitting an actual Pull Request](#before-submitting-an-actual-pull-request)
* [When you are ready to submit the Pull Request](#when-you-are-ready-to-submit-the-pull-request)
* [Troubleshooting](#troubleshooting)
## What this script automates:| Name | Description |
| --- | --- |
| Git Commit Push | Pushing local commits to remote branch with `git push`. |
| PR Creation | Clicking create a pull request from the feature branch in Github. |
| Target Merge Branch | Selecting the target branch to merge changes into. |
| PR Title | Copying the story name of the Jira ticket as the title of the pull request. |
| Jira Ticket Link | Adding the link of the Jira ticket to the pull request description. |
| Jira Ticket Description | Adding a description and acceptance criteria from the Jira ticket to the pull request. |
| PR Reviewers | Adding the reviewers of the pull request. |
| PR Assignee | Assigning the pull request owner as the assignee to the pull request. |
| Jira Ticket Comments | Adding all Jira comments from the associated ticket. |
| Jira Ticket Subtasks | Adding all Jira subtasks and subtask statuses, checked checkbox if completed. |
| Jira Team, Sprint, Goal, Components & Epic | Adding a section with the team name, sprint, and epic. |
| Jira Steps to Reproduce | Adding steps to reproduce if they exist, otherwise N/A. |
| GitHub Commit Hashes | Adding the updates section, a list of all commits with hashes and commit descriptions. |
| GitHub Diff | Adding a code changes section with the git diff of all code modifications. |
| Jira Ticket Screenshots | Adding screenshots for UI modifications or functionality improvements. (Optional - 3 Maximum) |
| GitHub PR Labels | Adding labels to categorize pull requests as a Story, Bug, QA, UAT, etc. Also adds team labels - ex. Automation, NSS_Automation (Optional) |
## Requirements
> [!IMPORTANT]
> For the public script (`public-pr-script.sh`), there are fewer requirements: GitHub CLI (hub), GitHub Token (PAT - set in .bash_profile or .zshrc), Gemini AI API Key (set in .bash_profile or .zshrc), GitHub reviewers (Code reviewer GitHub usernames) and GitHub assignee (your GitHub username) in .bash_profile or .zshrc (***`reviwers` and `assignee` are both optional**).| Name | Description | Link, Location, or Command |
| --- | --- | --- |
| `hub` | GitHub CLI - Adds additional GitHub commands to access the API from the CLI. | [hub](https://hub.github.com/) |
| `jq` | Command-line JSON processor - Parsing the response data from the Jira API. | [jq](https://stedolan.github.io/jq/download/) |
| `GitHub Personal Access Token - PAT` | Personal access tokens can be used instead of a password for Git over HTTPS, or can be used to authenticate to the API over Basic Authentication. * ***Note*** * `repo` permissions are required for this script to function properly. | [Create A GitHub Personal Access Token](https://github.com/settings/tokens) |
| `Jira API Token` | API tokens can authenticate scripts or other process with Atlassian cloud products. | [Create a JIRA Token](https://id.atlassian.com/manage-profile/security/api-tokens) |
| `.sh` | Shell file that automates creating pull requests using Jira ticket data, images, and other details. | Static location on your local computer - `touch pr_script.sh` |
| `PULL_REQUEST_TEMPLATE` | A pull request template to be used if a template does not exist in the repo. | Static location on your local computer - `PULL_REQUEST_TEMPLATE` in the same folder as `pr_script.sh` |
| `Environment Variables` | Environment variables that are stored in the terminal/bash/zsh configuration. Includes: `.sh` path alias, `jira_url`, `jira_access_token`, `github_author` and `github_reviewers` | `~/.bash_profile` or `~/.zshrc` - open with `open ~/.bash_profile` or `open ~/.zshrc` - then load with `source ~/.bash_profile` or `source ~/.zshrc` |
| `Git Bash` ***Required for Windows** | Git Bash provides a UNIX command line emulator for windows which can be used to run Git, shell commands, and much more. | [Download Git Bash](https://gitforwindows.org/) |## Mac Installation
Mac Instructions
##### 1. Install [hub](https://hub.github.com/).
```bash
brew install hub
```##### 2. Install [jq](https://stedolan.github.io/jq/download/).
```bash
brew install jq
```![jjjqqq](https://github.com/wesleyscholl/github-jira-pr-script/assets/128409641/b68cde56-37f9-4e63-9d00-bba309485665)
##### 4. [Create A GitHub Personal Access Token](https://github.com/settings/tokens) with `repo` permissions. Copy this token and keep for use later.
##### 5. Configure the GitHub hub configuration:
```bash
git config --global hub.protocol https
git config --global hub.user [your github username]
git config --global hub.token [your github personal access token]
```##### 6. [Create a JIRA Token](https://id.atlassian.com/manage-profile/security/api-tokens). Also copy this token and keep for use later.
##### 7. Create a local `pr_script.sh` file - Run the following command: `touch pr_script.sh`.
```bash
touch pr_script.sh
```##### 8. Copy and paste the [pull request script template](https://raw.githubusercontent.com/wesleyscholl/github-jira-pr-script/main/automated-pr.sh) to your `pr_script.sh` file, then save the file.
##### 9. Open your terminal/bash/zsh configuration, `open ~/.bash_profile` or `open ~/.zshrc`.
```bash
open ~/.bash_profile
```
or
```bash
open ~/.zshrc
```
##### 10. Fill in the following bash configuration values:
```bash
alias pr='.sh'
export jira_url=https://totalwine.atlassian.net/
export jira_access_token=:
export github_author=
export github_reviewers=
```
Example:```bash
alias pr='/Users/wscholl/pr_script.sh'
export jira_url=https://totalwine.atlassian.net/
export [email protected]:AT***...***0A
export github_author=wesleyscholl
export github_reviewers=naimish1083,KevinArce98,kareewongsagul
```##### 11. Load the file with the source command:
```bash
source ~/.bash_profile
```
or
```bash
source ~/.zshrc
```##### 12. You can now execute the script to automate your pull request, the target branch is optional and defaults to `develop`.
```bash
pr
```
## Windows Installation
Windows Instructions
#### 1. Scoop is required to install `hub`, if it's not installed on your machine open a powershell window and run:
##
```powershell
> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
> irm get.scoop.sh | iex
```##
#### 2. Then install `hub`:
##
```powershell
> scoop install hub
```
##
#### 3. Use scoop to install `jq`:
##
```powershell
> scoop install jq
```##
#### 4. [Create A GitHub Personal Access Token](https://github.com/settings/tokens) with `repo` permissions. Copy this token and keep for use later.
####
#### 5. Install Git Bash from the Software Center App:
##
Click Search on the Microsoft Toolbar and type in `software center`.![Screenshot 2023-11-10 at 1 29 12 PM](https://github.com/wesleyscholl/github-jira-pr-script/assets/128409641/22e47f35-ed18-4079-8b2a-06a2a8ab0498)
Open the application and click on Git Bash to install.
![Screenshot 2023-11-10 at 1 27 36 PM](https://github.com/wesleyscholl/github-jira-pr-script/assets/128409641/deb69ae4-7658-4782-bbab-fe5b81763d20)
##
#### 6. Copy the `pr_script.sh` file from the `github-jira-pr-script` repo or create a new file in your C:/Users// folder:
##
Powershell:
```powershell
> New-Item -Type File -Path pr_script.sh
```Or Git Bash.
```bash
touch pr_script.sh
```##
#### 7. Open a git bash window and set the hub configuration using the following commands:
##
Ensure you update `` with your github username and `` with your github personal access token.```bash
git config --global hub.protocol https
git config --global hub.user
git config --global hub.token
```##
#### 8. Create a JIRA Token
##
[Create a JIRA Token](https://id.atlassian.com/manage-profile/security/api-tokens) and copy for use later.
##
#### 9. Create and open your bash configuration, `~/.bash_profile`.
##
In the same directory:```bash
touch .bash_profile
```Then:
```bash
notepad .bash_profile
```
And complete the following configuration:
```bash
alias pr='sh C:/Users//pr_script.sh'
export jira_url=https://totalwine.atlassian.net/
export jira_access_token=:
export github_author=
export github_reviewers=
```
Example:```bash
alias pr='sh C:/Users/WScholl/pr_script.sh'
export jira_url=https://totalwine.atlassian.net/
export [email protected]:AT***...***0A
export github_author=wesleyscholl
export github_reviewers=naimish1083,KevinArce98,kareewongsagul
```****Make sure you copy the full Jira token string into the `.bash_profile` configuration.***
##
#### 10. Load the `.bash_profile` configuration with the source command:
##
```bash
source ~/.bash_profile
```
##
#### 11. You can now execute the script to automate your pull request creation. Target branch is optional, defaults to `develop`.
##
```bash
pr
```
****Only run the `pr` command from a Total Wine Labs git repository feature branch, otherwise it will fail.***
## Before submitting an actual Pull Request
The pull request function has been commented out to ensure that the pull request looks good before creating a live Pull Request. The script will output text similar to the example below.
**Example Script Pull Request Output:**
```md
CRS-41964 NSS - 2.1 | Disable "Free State" data field - Story# [**CRS-41964**](https://totalwine.atlassian.net/browse/CRS-41964) NSS - 2.1 | Disable "Free State" data field - Story
### Description
As a user,I want the "Free Goods State" data field to be disabled and set to "No" to simplify data entryas filling this field is not required.
##
#### Comments
- Finished development, wrote unit test to ensure input is disabled.!Screenshot 2023-11-08 at 2.09.51 PM.png|width=391,height=368!
##
#### Subtasks
- [x] Development - Done
- [ ] QA Validation - Code Review
- [ ] PO Approval - Open
##
> Team Pluto
> 23-23 - Team Pluto
> NSS - 2.1 | Post MVP
##
## Steps to Reproduce
- N/A## Updates
* list of updates
7c1e712 CRS-41964 - Updated input value according to acceptance criteria
41b99c4 CRS-41964 - Free Goods State input now disabled, added unit test to test input is disabled## Code Changes
* list of code changes+diff --git a/src/components/SupplyChain/StoreContainer.test.tsx b/src/components/SupplyChain/StoreContainer.test.tsx
+index 437e1b4..1983103 100644
+--- a/src/components/SupplyChain/StoreContainer.test.tsx
++++ b/src/components/SupplyChain/StoreContainer.test.tsx
+@@ -185,4 +185,12 @@ describe('StoreContainer', () => {
+
+ expect(setSupplyChainData).toHaveBeenCalled();
+ });
++
++ it('should disable "Free Goods State" input when freeGoodsStateInput prop is true', () => {
++ const wrapper = shallow();
++ const freeGoodsStateInput = wrapper.find(
++ 'Select[name="nss-store-supply-chain-free-goods-select"]'
++ );
++ expect(freeGoodsStateInput.prop('disabled')).toBe(true);
++ });
+ });
+diff --git a/src/components/SupplyChain/StoreContainer.tsx b/src/components/SupplyChain/StoreContainer.tsx
+index 63955cd..2c2b358 100644
+--- a/src/components/SupplyChain/StoreContainer.tsx
++++ b/src/co## Screen Shots
![Screen Shot](https://api.media.atlassian.com/file/f6bef5ab-a4b5-4e28-ab32-2a197b719c42/binary?token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI5NTI3ZWFkMC1mMDFjLTQ3NjMtYTdlNC04Y2UxNzk1ZWM0NTIiLCJhY2Nlc3MiOnsidXJuOmZpbGVzdG9yZTpmaWxlOmY2YmVmNWFiLWE0YjUtNGUyOC1hYjMyLTJhMTk3YjcxOWM0MiI6WyJyZWFkIl19LCJleHAiOjE2OTk0NzIwODcsIm5iZiI6MTY5OTQ3MTQ4N30.2gBkYLD_8Y-_pEsraxRH69bnxe0E4WlB3J25wE32k70&client=9527ead0-f01c-4763-a7e4-8ce1795ec452&dl=true&name=Screenshot+2023-11-08+at+2.09.51+PM.png)
```## When you are ready to submit the Pull Request
**Uncomment these lines at the bottom of the `pr_script.sh` and run `pr `.**
```bash
# if [ -z "$label" ]; then
# hub pull-request -b $base_branch -F PR_MESSAGE --no-edit -o -r $reviewers -a $assign
# else
# hub pull-request -b $base_branch -F PR_MESSAGE --no-edit -o -r $reviewers -a $assign -l $label
# fi
```
***Once the script completes, it will open the newly created PR in the default web browser. It should look like the following example.**## Example Created Pull Request
##
## Troubleshooting#### fatal: not a git repository (or any of the parent directories): .git
##
![Screenshot 2023-11-10 at 1 56 17 PM](https://github.com/wesleyscholl/github-jira-pr-script/assets/128409641/e9cc37fd-69a7-412d-9fdc-dd78f6676de7)This error message displays when the pr script is run from a non .git repository folder. Run the `pr` command from the feature branch within a Total Wine Labs repository.
##
#### command not found: pr_script.sh
##
If you see this message, the environment variables haven't been loaded or the alias syntax is incorrect.- Update your alias to the following syntax: `alias pr='/Users/wscholl/pr_script.sh'` Update the path if your pr_script.sh file is in a different location.
- Load the bash/zsh/terminal configuration environment variables with the following command:
```bash
source ~/.bash_profile
```
or
```bash
source ~/.zshrc
```
##
#### Forbidden HTTP 403 - Resource protected by organization SAML enforcement. You must grant your Personal Access token access to this organization.
##
This means that the GitHub personal access token (PAT) needs authorization to access the TotalWineLabs organization.- To do this, go to https://github.com/settings/tokens. Click "Configure SSO" on your pull request token. Authorize the token to access the TotalWineLabs organization.
- When the token has been properly authorized, you should see "Deauthorize" under single sign-on organizations next to TotalWineLabs.
##
#### Permission Denied Error
##
If you receive this error, execute one of the following commands:```bash
chmod +x pr
```
or
```bash
chmod +x path of the script.sh
```
##
#### Terminal/bash/zsh config file not found
##
Use the following commands to create the file:
```bash
touch ~/.bash_profile
```
or
```bash
touch ~/.zshrc
```
After you’ve created the file, open it with `open ~/.bash_profile` or `open ~/.zshrc` and add the environment variables to it.
##
#### Cannot execute: required file not found error
##If you see this message, the `.bash_profile` alias is not configured properly.
```bash
bash: C:/Users//pr_script.sh: cannot execute: required file not found
```Modify this line:
```bash
alias pr='C:/Users/WScholl/pr_script.sh'
```
to
```bash
alias pr='sh C:/Users/WScholl/pr_script.sh'
```Windows requires the `sh` command to be specified in the alias.