Skip to content

Commit 6799cd6

Browse files
authored
Merge pull request #1 from aws-github-ops/khushail/handleStaleDiscussion_ver1
initial commit
2 parents ae16a91 + 260c579 commit 6799cd6

33 files changed

+55835
-5
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
[*]
3+
end_of_line = lf
4+
charset = utf-8
5+
insert_final_newline = true
6+
indent_style = space
7+
indent_size = 2
8+
9+
[Makefile]
10+
indent_style = tab
11+
intent_size = 4

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

.eslintrc.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
extends:
3+
- eslint:recommended
4+
- plugin:node/recommended
5+
- prettier
6+
plugins:
7+
- node
8+
- prettier
9+
rules:
10+
prettier/prettier: error
11+
block-scoped-var: error
12+
eqeqeq: error
13+
no-var: error
14+
prefer-const: error
15+
eol-last: error
16+
prefer-arrow-callback: error
17+
no-trailing-spaces: error
18+
quotes:
19+
- warn
20+
- single
21+
- avoidEscape: true
22+
no-restricted-properties:
23+
- error
24+
- object: describe
25+
property: only
26+
- object: it
27+
property: only
28+
overrides:
29+
- files:
30+
- "**/**.ts"
31+
- "**/**.tsx"
32+
parser: "@typescript-eslint/parser"
33+
plugins:
34+
- "@typescript-eslint"
35+
extends:
36+
- plugin:@typescript-eslint/recommended
37+
- plugin:@typescript-eslint/recommended-requiring-type-checking
38+
rules:
39+
"@typescript-eslint/no-non-null-assertion": 'off'
40+
"@typescript-eslint/no-misused-promises": ["error", {"checksvoidReturn": false}]
41+
node/no-missing-import: 'off'
42+
node/no-empty-function: 'off'
43+
node/no-unsupported-features/es-syntax: 'off'
44+
node/no-missing-require: 'off'
45+
node/shebang: 'off'
46+
node/no-unpublished-import:
47+
- error
48+
parserOptions:
49+
project: './tsconfig.json'
50+
ecmaVersion: 2018
51+
sourceType: module
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: LabelAnswerableDiscussions
2+
on:
3+
schedule:
4+
- cron: '*/30 * * * *'
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
12+
jobs:
13+
run-action:
14+
name: Run action
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Use Node.js 16.x
21+
uses: actions/setup-node@v2
22+
with:
23+
node-version: 16.x
24+
cache: 'npm'
25+
cache-dependency-path: package-lock.json
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Build
31+
run: npm run build
32+
33+
- name: Close stale discussions
34+
uses: ./
35+
env:
36+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
37+
DEFAULT_BRANCH: master

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.prettierrc.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
---
3+
bracketSpacing: true
4+
singleQuote: true
5+
trailingComma: es5
6+
arrowParens: avoid
7+
printWidth: 120

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
## My Project
1+
## AWS Stale Discussion Bot
22

3-
TODO: Fill this README out!
3+
* Purpose: OSDS will mark discussion answers as proposed-answer and after N number of days, the bot will go in and automatically mark that answer as the discussion answer.
44

5-
Be sure to:
5+
* Normal case: Discussion is opened, OSDS answers it, says @bot propose-answer.
6+
Bot then comments the thread with instructions to the customer. If the customer
7+
marks the discussion as answered, the bot removes the proposed-answer comment
8+
and any replies it made on the thread and closes the discussion as resolved. If the customer does not mark the discussion as answered, the bot ask OSDS to take another look and help the customer.
69

7-
* Change the title in this README
8-
* Edit your repository description on GitHub
10+
* Edge case: The submitter thumbs down the proposed-answer. If that happens, the bot will comment with a mention to the OSDS team member that the answer is not right, to take another look.
11+
* Edge case: The discussion gets locked. Bot will take no action on locked
12+
discussions.
13+
* Edge case: The discussion gets moved. Bot should take normal actions on moved
14+
discussions unless it gets moved into a category that's not answerable, in which case the bot will comment that it's unable to do anything further.
15+
* Edge case: Bot waits for submitter's response on the suggested answer. If there is no response after 7 days, a reminder is sent to submitter to take action on proposed answer. In absence of response for next 4 days, discussion is closed as being stale.
16+
* Edge case: There are multiple proposed answers. Newer proposed answers will take precedence over older ones.
17+
18+
## Setup
19+
20+
Follow this [Setup guide](handle-stale-discussions/SETUP.md).
921

1022
## Security
1123

SETUP.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
## Run below commands for the installing the required packages
2+
- npm install --save graphql
3+
- npm install --save-dev typescript ts-node
4+
- npm install @actions/github
5+
6+
### Generating types from Github Graphql Schema
7+
* Run below commands
8+
```
9+
npm install --save-dev @octokit/graphql-schema @graphql-codegen/cli
10+
11+
npx graphql-codegen init
12+
13+
```
14+
* After you run above statement, select below options for setup-
15+
- What type of application are you building? ◉ Backend - API or server
16+
- Where is your schema?: src/generated/github-schema-loader.ts
17+
- Pick plugins:
18+
◉ TypeScript (required by other typescript plugins)
19+
◉ TypeScript Resolvers (strongly typed resolve functions)
20+
◯ TypeScript MongoDB (typed MongoDB objects)
21+
❯◉ TypeScript GraphQL document nodes (embedded GraphQL document)
22+
- Where to write the output: (src/generated/graphql.ts)
23+
- Do you want to generate an introspection file? (Y/n) n
24+
- How to name the config file? (codegen.yml)
25+
- What script in package.json should run the codegen? codegen
26+
* Run these commands
27+
```
28+
npm install
29+
30+
npm install --save @apollo/client cross-fetch
31+
32+
npm install --save-dev @graphql-codegen/typescript-operations
33+
34+
npm run codegen
35+
36+
```
37+
If there is error in generating the codegen with above command, pls copy/paste this code in codegen.yml file and rerun the command ``` npm run codegen```
38+
39+
```
40+
# codegen.yml
41+
overwrite: true
42+
schema: "src/generated/github-schema-loader.ts"
43+
generates:
44+
src/generated/graphql.ts:
45+
plugins:
46+
- "typescript"
47+
- "typescript-resolvers"
48+
- "typescript-document-nodes"
49+
- "typescript-operations"
50+
51+
require:
52+
- ts-node/register
53+
54+
documents:
55+
- src/queries/*.graphql
56+
- src/mutations/*.graphql
57+
```
58+
59+
### Updating schema
60+
* Run this command - ```npm update @octokit/graphql-schema```
61+
62+
Once schema is updated, rerun the command to update codegen file -``` npm run codegen```
63+
64+
## Testing with Jest framework
65+
* Install by running this - ```npm install --save-dev jest```
66+
- Add following to your Package.json
67+
68+
`
69+
{
70+
"scripts": {
71+
"test": "jest"
72+
}
73+
}
74+
`
75+
* Finish the setup by running these -
76+
77+
```
78+
npm install --save-dev ts-jest
79+
80+
npm install --save-dev @jest/globals
81+
82+
npm install --save-dev @types/jest
83+
84+
npx ts-jest config:init
85+
```

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: 'Handle stale discussions'
2+
description: 'Custom GH action on discussions'
3+
4+
runs:
5+
using: 'node16'
6+
main: 'dist/index.js'

codegen.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# codegen.yml
2+
overwrite: true
3+
schema: "src/generated/github-schema-loader.ts"
4+
generates:
5+
src/generated/graphql.ts:
6+
plugins:
7+
- "typescript"
8+
- "typescript-resolvers"
9+
- "typescript-document-nodes"
10+
- "typescript-operations"
11+
12+
require:
13+
- ts-node/register
14+
15+
documents:
16+
- src/queries/*.graphql
17+
- src/mutations/*.graphql

0 commit comments

Comments
 (0)