Skip to content

Commit f9eb60b

Browse files
committed
Use repo param
1 parent 6ff2c62 commit f9eb60b

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
curl --header "Content-Type: application/json" \
1515
--request POST \
1616
--data '{"event":"entry.create","created_at":"2020-01-10T08:47:36.649Z","model":"example","entry":{}}' \
17-
"http://localhost:5000/api?event_type=strapi_updated&repo=badsyntax/example"
17+
"http://localhost:5000/api?event_type=strapi_updated&repo=badsyntax/thirlby-village"
1818
```
1919

2020
## Build, Run, Publish Docker Image

src/app.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import 'isomorphic-fetch';
55

66
dotenv.config();
77

8+
const { GITHUB_TOKEN } = process.env;
9+
if (!GITHUB_TOKEN) {
10+
throw new Error('Env not set correctly');
11+
}
12+
813
import { indexRoute } from './routes/api/index';
914

1015
const app = express();

src/routes/api/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@ indexRoute.post(
88
req: Request<null, ResponseBody, RequestBody, QueryParams>,
99
res: Response<ResponseBody>
1010
) => {
11-
const { DISPATCHES_ENDPOINT, GITHUB_TOKEN } = process.env;
12-
if (!DISPATCHES_ENDPOINT || !GITHUB_TOKEN) {
13-
throw new Error('Env not set correctly');
14-
}
15-
const { event_type: eventType } = req.query;
11+
const { event_type: eventType, repo } = req.query;
1612
if (!eventType) {
1713
return res.status(400).send('event_type param missing');
1814
}
15+
if (!repo) {
16+
return res.status(400).send('repo param missing');
17+
}
1918
try {
20-
await fetch(DISPATCHES_ENDPOINT, {
19+
await fetch(`https://api.github.com/repos/${repo}/dispatches`, {
2120
method: 'post',
2221
headers: new Headers({
2322
Accept: 'application/vnd.github.v3+json',
24-
Authorization: `token ${GITHUB_TOKEN}`,
23+
Authorization: `token ${process.env.GITHUB_TOKEN}`,
2524
ContentType: 'application/json',
2625
}),
2726
body: JSON.stringify({ event_type: eventType }),

src/routes/api/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export type ResponseBody = string;
22

33
export type QueryParams = {
44
event_type: string;
5+
repo: string;
56
};
67

78
export enum EventType {

0 commit comments

Comments
 (0)