Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@

# Discord gcloud build bot


## Generate Github token
Setting > Developer settings > Personal access tokens


selects following scopes

- [x] repo
- [x] repo:status
- [x] repo_deployment
- [x] public_repo
- [x] repo:invite
- [x] security_events
- [ ] user
- [x] read:user
- [x] user:email

To deploy to cloud function
## To deploy to cloud function



Expand All @@ -21,7 +32,7 @@ and run following command,

```

gcloud functions deploy subscribeDiscord --trigger-topic cloud-builds --runtime nodejs10 --env-vars-file .env.yaml
gcloud functions deploy subscribeDiscord --trigger-topic cloud-builds --runtime nodejs14 --env-vars-file .env.yaml

```

Expand Down
122 changes: 0 additions & 122 deletions index.js

This file was deleted.

13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
"name": "nimble-build-notification",
"version": "1.0.0",
"description": "",
"main": "index.js",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"deploy": "gcloud functions deploy subscribeDiscord --env-vars-file .env.yaml"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.21.2"
"axios": "^0.21.2",
"moment": "^2.29.1",
"moment-timezone": "^0.5.34"
},
"devDependencies": {
"@types/node": "^14.0.14",
Expand Down
9 changes: 6 additions & 3 deletions src/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ const capitalized = (textString: string) => {

export const getTitle = ({
repo,
branch,
target,
status,
}: {
repo: string;
branch: string;
target: string;
status: string;
}): string => `${repo}(${branch}) is ${capitalized(status)}`;
}): string => `${repo}(${target}) is ${capitalized(status)}`;

export const getUrl = (message: string, url: string): string =>
`[${message}](${url})`;
33 changes: 24 additions & 9 deletions src/github.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import axios, { AxiosPromise, AxiosResponse } from 'axios';
import { CommitResponse } from './interfaces';
import { CommitResponse, ErrorResponse } from './interfaces';

export const getMessage = (result: AxiosResponse<CommitResponse>): string => {
type Repo = CommitResponse['data']['repository']['object'];

export const isError = (
payload: AxiosResponse<CommitResponse | ErrorResponse>
): payload is AxiosResponse<ErrorResponse> => {
return 'errors' in payload.data;
};

export const getRepository = (result: AxiosResponse<CommitResponse>): Repo => {
try {
return result.data.data.repository.object.message;
return result.data.data.repository.object;
} catch (error) {
return error;
}
Expand All @@ -15,19 +23,26 @@ export const fetchGitMessage = ({
owner,
}: {
[k: string]: string;
}): AxiosPromise<CommitResponse> => {
return axios.post(
'https://api.github.com/graphql',
{
query: `{
}): AxiosPromise<CommitResponse | ErrorResponse> => {
const query = `{
repository(owner:"${owner}",name:"${repo}") {
object(oid: "${commit}") {
... on Commit {
message
committedDate
author {
avatarUrl
name
}
}
}
}
}`,
}`;
console.log({ query });
return axios.post(
'https://api.github.com/graphql',
{
query,
},
{
headers: {
Expand Down
Loading