Skip to content

Gets open pull requests from the github graphql api and posts summary information to a slack channel

Notifications You must be signed in to change notification settings

nick-myers/msg-summary-git-pull-requests-to-slack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Purpose

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.

Pre-requisites

  1. You will need a Personal Access Token from github
  2. 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)

Installation and usage

  1. Install node.js - https://nodejs.org/
  2. 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
  1. Clone this repository to a directory of your choosing
  2. Initialise typescript in the directory you cloned the repo into
  • npm run tsc -- --init
  1. Create /src/config.ts and populate it as described below
  2. 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

Configuration

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';

Transpile

  1. Run tsc (this transpiles the TypeScript code (.ts) into JavaScript (.js) )
  2. Confirm that /build/config.js and /build/g2s.js have been created

Execute

  1. Run node ./build/g2s.js
  2. Confirm that a message was pushed to Slack

Scheduling

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.

  1. In the task schedule, I added an action that called the program: C:\nodejs\node.exe
  2. I added the argument with the full path to the javascript file C:\Users\nick.myers\Documents\GitHub\g2s\build\g2s.js

Example output (as a slack message)

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

About

Gets open pull requests from the github graphql api and posts summary information to a slack channel

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published