generated from ctc-uci/npo-backend-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit db6533e
Showing
19 changed files
with
3,097 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# EditorConfig is awesome: https://editorconfig.org/ | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Use unix-style newlines with a newline ending every file | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.{md,json}] | ||
insert_final_newline = false | ||
|
||
[.*] | ||
insert_final_newline = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": [ | ||
"airbnb-base", | ||
"plugin:prettier/recommended" | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": 13, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: CI | ||
|
||
on: | ||
[pull_request] | ||
|
||
permissions: read-all | ||
|
||
jobs: | ||
eslint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: '16' | ||
- run: yarn install | ||
- name: Run eslint with reviewdog | ||
uses: reviewdog/[email protected] | ||
with: | ||
github_token: ${{ secrets.CTC_DEVOPS_ORG_PAT }} | ||
reporter: github-pr-review | ||
fail_on_error: false | ||
eslint_flags: '**/*.{js,jsx}' | ||
|
||
detect-secrets: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Run detect-secrets with reviewdog | ||
uses: reviewdog/action-detect-secrets@master | ||
with: | ||
github_token: ${{ secrets.CTC_DEVOPS_ORG_PAT }} | ||
reporter: github-pr-review | ||
|
||
# Prevents false positives from failing job | ||
fail_on_error: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: Heroku Build Logs | ||
on: deployment_status | ||
|
||
jobs: | ||
heroku-build-logs: | ||
name: Heroku Build Logs | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Heroku Build Logs | ||
uses: ctc-uci/github-action-heroku-logs@master | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
HEROKU_AUTH_TOKEN: ${{ secrets.CTC_HEROKU_API_KEY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Issue Assigned | ||
|
||
on: | ||
issues: | ||
types: [assigned] | ||
jobs: | ||
slack_message_assignee: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: borales/[email protected] | ||
with: | ||
cmd: add @slack/bolt mongoose | ||
- uses: actions/github-script@v6 | ||
env: | ||
SLACK_TOKEN: ${{ secrets.CTC_SLACKBOT_OAUTH_TOKEN }} | ||
SIGNING_SECRET: ${{ secrets.CTC_SLACKBOT_SIGNING_SECRET }} | ||
APP_LEVEL_TOKEN: ${{ secrets.CTC_SLACKBOT_APP_LEVEL_TOKEN }} | ||
MONGO_URI: ${{ secrets.CTC_SLACKBOT_MONGO_URI }} | ||
with: | ||
script: | | ||
const messageAssignee = require('./.github/workflows/scripts/issueAssigned'); | ||
await messageAssignee({context}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: PR Reviewer Requested | ||
|
||
on: | ||
pull_request: | ||
types: [review_requested] | ||
jobs: | ||
slack_message_reviewer: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: borales/[email protected] | ||
with: | ||
cmd: add @slack/bolt mongoose | ||
- uses: actions/github-script@v6 | ||
env: | ||
SLACK_TOKEN: ${{ secrets.CTC_SLACKBOT_OAUTH_TOKEN }} | ||
SIGNING_SECRET: ${{ secrets.CTC_SLACKBOT_SIGNING_SECRET }} | ||
APP_LEVEL_TOKEN: ${{ secrets.CTC_SLACKBOT_APP_LEVEL_TOKEN }} | ||
MONGO_URI: ${{ secrets.CTC_SLACKBOT_MONGO_URI }} | ||
with: | ||
script: | | ||
const messageReviewer = require('./.github/workflows/scripts/reviewRequested'); | ||
await messageReviewer({context}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: PR Reviewed | ||
|
||
on: | ||
pull_request_review: | ||
types: [submitted] | ||
jobs: | ||
slack_message_assignee: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: borales/[email protected] | ||
with: | ||
cmd: add @slack/bolt mongoose | ||
- uses: actions/github-script@v6 | ||
env: | ||
SLACK_TOKEN: ${{ secrets.CTC_SLACKBOT_OAUTH_TOKEN }} | ||
SIGNING_SECRET: ${{ secrets.CTC_SLACKBOT_SIGNING_SECRET }} | ||
APP_LEVEL_TOKEN: ${{ secrets.CTC_SLACKBOT_APP_LEVEL_TOKEN }} | ||
MONGO_URI: ${{ secrets.CTC_SLACKBOT_MONGO_URI }} | ||
with: | ||
script: | | ||
const messageAssignee = require('./.github/workflows/scripts/reviewReviewed'); | ||
await messageAssignee({context}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const { App } = require('@slack/bolt'); | ||
const mongoose = require('mongoose'); | ||
|
||
const getUserModel = () => { | ||
const userSchema = new mongoose.Schema({ | ||
slackId: { type: String, required: true }, // Slack user ID | ||
slackName: { type: String, required: true }, // Slack user name | ||
role: { type: String, required: true }, // "ADMIN" | "TECHLEAD" | "MEMBER" | ||
repos: { type: Array, required: true }, // List of assigned projects | ||
github: { type: String, required: true }, | ||
rep: { type: Number, required: true }, // Reputation count | ||
matchyEnabled: { type: Boolean, required: true }, // Opted into Matchy or not | ||
}); | ||
return mongoose.model('User', userSchema); | ||
}; | ||
|
||
const messageAssignee = async ({ context }) => { | ||
// Initializes your app with your bot token and signing secret | ||
const Bot = new App({ | ||
token: process.env.SLACK_TOKEN, | ||
signingSecret: process.env.SIGNING_SECRET, | ||
socketMode: true, | ||
appToken: process.env.APP_LEVEL_TOKEN, | ||
}); | ||
|
||
const assignee = context.payload.assignee.login; | ||
const url = context.payload.issue.html_url; | ||
|
||
// Connect to mongo | ||
mongoose.connect(process.env.MONGO_URI, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}); | ||
const mongoConnection = mongoose.connection; | ||
// After connection is established, DM assignee on Slack | ||
mongoConnection.once('open', async () => { | ||
try { | ||
const UserModel = getUserModel(); | ||
const user = await UserModel.findOne({ github: assignee }); | ||
await Bot.client.chat.postMessage({ | ||
channel: user.slackId, | ||
text: `You have been assigned to an <${url}|issue> for \`${context.payload.repository.name}\`! :worry-frog-cheer:`, | ||
}); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
mongoConnection.close(); | ||
}); | ||
}; | ||
|
||
module.exports = messageAssignee; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const { App } = require('@slack/bolt'); | ||
const mongoose = require('mongoose'); | ||
|
||
const getUserModel = () => { | ||
const userSchema = new mongoose.Schema({ | ||
slackId: { type: String, required: true }, // Slack user ID | ||
slackName: { type: String, required: true }, // Slack user name; do we want to keep track of this | ||
role: { type: String, required: true }, // "ADMIN" | "TECHLEAD" | "MEMBER" - defined in config/perms.js | ||
repos: { type: Array, required: true }, // List of assigned projects | ||
github: { type: String, required: true }, | ||
rep: { type: Number, required: true }, // Reputation count | ||
matchyEnabled: { type: Boolean, required: true }, // Opted into Matchy or not | ||
}); | ||
return mongoose.model('User', userSchema); | ||
}; | ||
|
||
const messageReviewer = async ({ context }) => { | ||
// Initializes your app with your bot token and signing secret | ||
const Bot = new App({ | ||
token: process.env.SLACK_TOKEN, | ||
signingSecret: process.env.SIGNING_SECRET, | ||
socketMode: true, | ||
appToken: process.env.APP_LEVEL_TOKEN, | ||
}); | ||
|
||
const sender = context.payload.sender.login; | ||
const reviewer = context.payload.requested_reviewer.login; | ||
const url = context.payload.pull_request.html_url; | ||
|
||
// Connect to mongo | ||
mongoose.connect(process.env.MONGO_URI, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}); | ||
const mongoConnection = mongoose.connection; | ||
// After connection is established, DM reviewer on Slack | ||
mongoConnection.once('open', async () => { | ||
try { | ||
const UserModel = getUserModel(); | ||
const user = await UserModel.findOne({ github: reviewer }); | ||
await Bot.client.chat.postMessage({ | ||
channel: user.slackId, | ||
text: `A review for a <${url}|PR> has been requested by ${sender}! :catjam:`, | ||
}); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
mongoConnection.close(); | ||
}); | ||
}; | ||
|
||
module.exports = messageReviewer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const { App } = require('@slack/bolt'); | ||
const mongoose = require('mongoose'); | ||
|
||
// commented, approved, changes_requested | ||
|
||
const getUserModel = () => { | ||
const userSchema = new mongoose.Schema({ | ||
slackId: { type: String, required: true }, // Slack user ID | ||
slackName: { type: String, required: true }, // Slack user name; do we want to keep track of this | ||
role: { type: String, required: true }, // "ADMIN" | "TECHLEAD" | "MEMBER" - defined in config/perms.js | ||
repos: { type: Array, required: true }, // List of assigned projects | ||
github: { type: String, required: true }, | ||
rep: { type: Number, required: true }, // Reputation count | ||
matchyEnabled: { type: Boolean, required: true }, // Opted into Matchy or not | ||
}); | ||
return mongoose.model('User', userSchema); | ||
}; | ||
|
||
const messageAssignee = async ({ context }) => { | ||
// Initializes your app with your bot token and signing secret | ||
const Bot = new App({ | ||
token: process.env.SLACK_TOKEN, | ||
signingSecret: process.env.SIGNING_SECRET, | ||
socketMode: true, | ||
appToken: process.env.APP_LEVEL_TOKEN, | ||
}); | ||
|
||
const reviewer = context.payload.sender.login; | ||
const githubAssignees = context.payload.pull_request.assignees; | ||
const url = context.payload.review.html_url; | ||
|
||
// Connect to mongo | ||
mongoose.connect(process.env.MONGO_URI, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}); | ||
const mongoConnection = mongoose.connection; | ||
// After connection is established, do the things | ||
mongoConnection.once('open', async () => { | ||
try { | ||
const UserModel = getUserModel(); | ||
const slackAssignees = await Promise.allSettled( | ||
githubAssignees.map(assignee => UserModel.findOne({ github: assignee.login })), | ||
); | ||
if (context.payload.review.state === 'approved') { | ||
await Promise.all( | ||
slackAssignees.map(assignee => | ||
Bot.client.chat.postMessage({ | ||
channel: assignee.value?.slackId, | ||
text: `One of your pull requests has been APPROVED by ${reviewer}! <${url}|View Review> :shrek::thumbsup:`, | ||
}), | ||
), | ||
); | ||
} else { | ||
await Promise.all( | ||
slackAssignees.map(assignee => | ||
Bot.client.chat.postMessage({ | ||
channel: assignee.value?.slackId, | ||
text: `One of your pull requests has been REVIEWED by ${reviewer}! <${url}|View Review> :shrek:`, | ||
}), | ||
), | ||
); | ||
} | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
mongoConnection.close(); | ||
}); | ||
}; | ||
|
||
module.exports = messageAssignee; |
Oops, something went wrong.