This script is used to retrieve open pull requests for an organisation from the github graphql api and post a summary of the information about them to a slack channel.
- You will need a Personal Access Token from github
- You will need to create an application for Slack, and get the OAuth token for the application (with at least the
chat:write:user
scope)
- Install node.js - https://nodejs.org/
- Use the node package manager (npm) to install the following packages:
npm install -g typescript
npm install @types/node
npm install @octokit/graphql
npm install moment
npm install moment-business-days
npm install @slack/web-api
npm install cisco-vpn
npm install ps-node
- Clone this repository to a directory of your choosing
- Initialise typescript in the directory you cloned the repo into
npm run tsc -- --init
- Create
/src/config.ts
and populate it as described below - Create a personal access token as per https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line
The content of the /src/config.ts
should be as follows:
export const gitUrl: string = 'https://www.github.com/api'; // Enterprise users should replace this with their own URL
export const pass: string = 'QUSV065T5P88NTQ9XHMA6CA184CPX2EUM4OR0BYF'; // Github personal access token - example is not a real token - select repo, gist and users scopes
export const oauthToken: string = 'xoxp-28841330430-452313974416-300102328521-k8eniubfprdxjp3m4fv65z7j1oc57lfy'; // Slack application oauth token - will start with xoxp- example is not a real token
export const channel: string = 'OJQY8BFJJ'; // Slack channel ID - example is not a real channel id
export const organisation: string = 'MyOrganisation'; // Github organisation name
export const vpnhost: string = 'remote.organisation.com';
export const vpnuser: string = 'your username';
export const vpnpass: string = 'your password'
export const vpnexe: string = 'C:\\Program Files (x86)\\Cisco\\Cisco AnyConnect Secure Mobility Client\\vpncli.exe';
- Run
tsc
(this transpiles the TypeScript code (.ts) into JavaScript (.js) ) - Confirm that
/build/config.js
and/build/g2s.js
have been created
- Run
node ./build/g2s.js
- Confirm that a message was pushed to Slack
On Windows 10 I used the built in Task Scheduler application, that would trigger the node application and pass the path to the javascript file as an argument.
- In the task schedule, I added an action that called the program:
C:\nodejs\node.exe
- I added the argument with the full path to the javascript file
C:\Users\nick.myers\Documents\GitHub\g2s\build\g2s.js
repository-1 has 2 open pull request(s):
• 2 days old: Feature/APP-1234 Makes changes - https://www.github.com/organisation/repository-1/pull/25
• 6 days old: Feature/APP-1236 Makes changes to the secondary api… - https://www.github.com/organisation/repository-1/pull/24
repository-2 has 1 open pull request(s):
• 11 days old: APP-1235 added tags - https://www.github.com/organisation/repository-2/pull/60
repository-3 has 2 open pull request(s):
• 6 days old: APP-1236: Updates node.js version to the latest version of 10 supported b… - https://www.github.com/organisation/repository-3/pull/75
• 11 days old: APP-1237 Added tags to the change set, this will add tags to all objec… - https://www.github.com/organisation/repository-3/pull/72