Skip to content

Commit 6d02542

Browse files
authored
Get token in GitHub webhooks (#1469)
1 parent f08a660 commit 6d02542

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

services/libs/integrations/src/integrations/github/processStream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const setTokenToCache = async (ctx: IProcessStreamContext, token: AppTokenRespon
8383
await cache.set(key, JSON.stringify(token), 5 * 60)
8484
}
8585

86-
async function getGithubToken(ctx: IProcessStreamContext): Promise<string> {
86+
export async function getGithubToken(ctx: IProcessStreamContext): Promise<string> {
8787
const auth = getAuth(ctx)
8888
if (auth) {
8989
let appToken: AppTokenResponse

services/libs/integrations/src/integrations/github/processWebhookStream.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import getMember from './api/graphql/members'
2020
import { prepareMember } from './processStream'
2121
import TeamsQuery from './api/graphql/teams'
2222
import { GithubWebhookTeam } from './api/graphql/types'
23-
import { processPullCommitsStream } from './processStream'
23+
import { processPullCommitsStream, getGithubToken } from './processStream'
2424

2525
const IS_TEST_ENV: boolean = process.env.NODE_ENV === 'test'
2626

@@ -44,7 +44,8 @@ const prepareWebhookMember = async (
4444
return null
4545
}
4646

47-
const member = await getMember(login, ctx.integration.token)
47+
const token = await getGithubToken(ctx as IProcessStreamContext)
48+
const member = await getMember(login, token)
4849

4950
if (!member) {
5051
ctx.log.warn(
@@ -196,7 +197,8 @@ const parseWebhookPullRequest = async (payload: any, ctx: IProcessWebhookStreamC
196197
if (payload.action === 'review_requested' && payload.requested_team) {
197198
// a team sent as reviewer, first we need to find members in this team
198199
const team: GithubWebhookTeam = payload.requested_team
199-
const teamMembers = await new TeamsQuery(team.node_id, ctx.integration.token).getSinglePage('')
200+
const token = await getGithubToken(ctx as IProcessStreamContext)
201+
const teamMembers = await new TeamsQuery(team.node_id, token).getSinglePage('')
200202

201203
for (const teamMember of teamMembers.data) {
202204
await parseWebhookPullRequestEvents({ ...payload, requested_reviewer: teamMember }, ctx)

0 commit comments

Comments
 (0)