Skip to content

Commit 8fc57e1

Browse files
added readme and updated package version (#16)
1 parent 57e4bc3 commit 8fc57e1

File tree

3 files changed

+153
-2
lines changed

3 files changed

+153
-2
lines changed

prBot/README.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# @hmcts/pr-bot
2+
3+
A bot to use within GitHub Actions that posts contextual information about pull requests to Slack.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @hmcts/pr-bot
9+
```
10+
11+
## Usage
12+
13+
### As a CLI tool
14+
15+
```bash
16+
npx pr-bot
17+
```
18+
19+
### Programmatically
20+
21+
```javascript
22+
const prBot = require('@hmcts/pr-bot');
23+
prBot.run();
24+
```
25+
26+
### Example Use In GitHub Actions Workflow
27+
28+
```yaml
29+
name: pr-bot
30+
on:
31+
pull_request:
32+
types: [opened, closed, reopened]
33+
pull_request_review:
34+
types: [submitted]
35+
36+
permissions:
37+
contents: read
38+
pull-requests: write
39+
issues: write
40+
41+
jobs:
42+
slack-notification:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Checkout respository
46+
uses: actions/checkout@v4
47+
48+
- name: Set up Node.js
49+
uses: actions/setup-node@v4
50+
with:
51+
node-version: '20'
52+
53+
- name: Azure CLI script
54+
uses: azure/cli@v2
55+
with:
56+
azcliversion: latest
57+
inlineScript: |
58+
# Log in to Azure using service principal
59+
az login --service-principal --username ${{ secrets.AZURE_CLIENT_ID }} --password ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
60+
61+
# Set the active subscription
62+
az account set --subscription ${{ secrets.AZURE_SUBSCRIPTION_ID_STG }}
63+
64+
# Get Slack token from Azure Key Vault
65+
SLACK_BOT_TOKEN=$(az keyvault secret show --name "exui-code-reviews-bot-slack-token" --vault-name "${{ secrets.AZURE_VAULT_NAME }}" --query "value" --output tsv)
66+
echo "::add-mask::$SLACK_BOT_TOKEN"
67+
echo "SLACK_BOT_TOKEN=$SLACK_BOT_TOKEN" >> $GITHUB_ENV
68+
69+
# Get token for data repo access from Azure Key Vault
70+
DATA_REPO_TOKEN=$(az keyvault secret show --name "${{ secrets.DATA_REPO_PAT_NAME }}" --vault-name "${{ secrets.AZURE_VAULT_NAME }}" --query "value" --output tsv)
71+
echo "::add-mask::$DATA_REPO_TOKEN"
72+
echo "DATA_REPO_TOKEN=$DATA_REPO_TOKEN" >> $GITHUB_ENV
73+
74+
- name: Parse PR_BOT_CONFIG_JSON github variable into environment variables
75+
run: |
76+
echo "REQUIRED_APPROVALS=$(echo $PR_BOT_CONFIG_JSON | jq -r '.REQUIRED_APPROVALS')" >> $GITHUB_ENV
77+
echo "TITLE_MAX_LENGTH=$(echo $PR_BOT_CONFIG_JSON | jq -r '.TITLE_MAX_LENGTH')" >> $GITHUB_ENV
78+
echo "DATA_REPO_OWNER=$(echo $PR_BOT_CONFIG_JSON | jq -r '.DATA_REPO_OWNER')" >> $GITHUB_ENV
79+
echo "DATA_REPO_NAME=$(echo $PR_BOT_CONFIG_JSON | jq -r '.DATA_REPO_NAME')" >> $GITHUB_ENV
80+
echo "DATA_STATE_FILE_PATH=$(echo $PR_BOT_CONFIG_JSON | jq -r '.DATA_STATE_FILE_PATH')" >> $GITHUB_ENV
81+
echo "SLACK_CHANNEL=$(echo $PR_BOT_CONFIG_JSON | jq -r '.SLACK_CHANNEL')" >> $GITHUB_ENV
82+
echo "SLACK_CHANNEL_ID=$(echo $PR_BOT_CONFIG_JSON | jq -r '.SLACK_CHANNEL_ID')" >> $GITHUB_ENV
83+
env:
84+
PR_BOT_CONFIG_JSON: ${{ vars.PR_BOT_CONFIG_JSON }}
85+
86+
- name: Run pr-bot
87+
run: |
88+
mkdir pr-bot-tmp
89+
cd pr-bot-tmp
90+
npx pr-bot
91+
env:
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
SLACK_BOT_TOKEN: ${{ env.SLACK_BOT_TOKEN }}
94+
DATA_REPO_TOKEN: ${{ env.DATA_REPO_TOKEN }}
95+
REQUIRED_APPROVALS: ${{ env.REQUIRED_APPROVALS }}
96+
TITLE_MAX_LENGTH: ${{ env.TITLE_MAX_LENGTH }}
97+
DATA_REPO_OWNER: ${{ env.DATA_REPO_OWNER }}
98+
DATA_REPO_NAME: ${{ env.DATA_REPO_NAME }}
99+
DATA_STATE_FILE_PATH: ${{ env.DATA_STATE_FILE_PATH }}
100+
SLACK_CHANNEL: ${{ env.SLACK_CHANNEL }}
101+
SLACK_CHANNEL_ID: ${{ env.SLACK_CHANNEL_ID }}
102+
```
103+
104+
## Configuration
105+
106+
### GitHub Secrets
107+
108+
The following secrets must be configured in your GitHub repository:
109+
110+
#### Azure Authentication (for accessing Key Vault)
111+
- `AZURE_CLIENT_ID` - Azure service principal client ID
112+
- `AZURE_CLIENT_SECRET` - Azure service principal client secret
113+
- `AZURE_TENANT_ID` - Azure tenant ID
114+
- `AZURE_SUBSCRIPTION_ID_STG` - Azure subscription ID
115+
- `AZURE_VAULT_NAME` - Name of the Azure Key Vault containing bot tokens
116+
- `DATA_REPO_PAT_NAME` - Name of the secret in Key Vault containing the data repo PAT
117+
118+
#### Required Secrets in Azure Key Vault
119+
- `exui-code-reviews-bot-slack-token` - Slack bot token (stored in Key Vault)
120+
- Personal access token with read/write permissions for data repo access (name specified by `DATA_REPO_PAT_NAME`)
121+
122+
The bot requires the following configuration variables:
123+
124+
#### Configuration Variables
125+
- `REQUIRED_APPROVALS` - Number of required approvals for PRs
126+
- `TITLE_MAX_LENGTH` - Maximum allowed length for PR titles
127+
- `DATA_REPO_OWNER` - Owner of the data repository
128+
- `DATA_REPO_NAME` - Name of the data repository
129+
- `DATA_STATE_FILE_PATH` - Path to the state file in the data repository
130+
- `SLACK_CHANNEL` - Slack channel name
131+
- `SLACK_CHANNEL_ID` - Slack channel ID
132+
133+
### GitHub Variables
134+
135+
You should store configuration variables as a stringified JSON object in the repository variables:
136+
137+
```json
138+
{"REQUIRED_APPROVALS":2,"TITLE_MAX_LENGTH":60,"DATA_REPO_OWNER":"owner","DATA_REPO_NAME":"name","DATA_STATE_FILE_PATH":"path/to/file.json","SLACK_CHANNEL":"channel","SLACK_CHANNEL_ID":"id"}
139+
```
140+
141+
## License
142+
143+
MIT - See [LICENSE.md](LICENSE.md) for details.
144+
145+
## Repository
146+
147+
[https://github.com/hmcts/rpx-xui-dev-utils/prBot](https://github.com/hmcts/rpx-xui-dev-utils/prBot)

prBot/RELEASE-NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Version 1.0.6
2+
EXUI-3114 Investigate automation tool to improve PR review process
3+
14
Version 1.0.5
25
EXUI-3114 Investigate automation tool to improve PR review process
36

prBot/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hmcts/pr-bot",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "A bot to be used in Github Actions which posts to Slack contextual information about pull requests.",
55
"main": "dist/index.js",
66
"bin": {
@@ -10,7 +10,8 @@
1010
"start": "node dist/prBot.js"
1111
},
1212
"files": [
13-
"dist"
13+
"dist",
14+
"README.md"
1415
],
1516
"keywords": [
1617
"github",

0 commit comments

Comments
 (0)