Skip to content

Commit 259301f

Browse files
authored
Merge pull request #637 from keymanapp/maint/upgrade-probot
maint: upgrade probot to 14.x
2 parents 4b6f944 + 410757c commit 259301f

9 files changed

Lines changed: 1346 additions & 3849 deletions

server/code.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { consoleLog } from './util/console-log.js';
2929
import { buildVersion } from '../shared/version.js';
3030
import { processGithubWebhookEvent } from './webhooks/github-webhook.js';
3131
import { triggerGitHookRedeliveryWorkflow } from './webhooks/github-webhook-redelivery.js';
32+
import { inspect } from 'node:util';
3233

3334
sms.install();
3435

@@ -225,7 +226,7 @@ wsServer.on('connection', socket => {
225226
});
226227

227228
export function reportError(error) {
228-
console.error(error);
229+
console.error(inspect(error));
229230
Sentry.captureMessage(error);
230231
}
231232

@@ -364,7 +365,7 @@ app.post('/webhook/discourse', (request, response) => {
364365
response.send('ok');
365366
});
366367

367-
app.use('/webhook/keymanapp-test-bot', keymanAppTestBotMiddleware);
368+
app.use('/webhook/keymanapp-test-bot', (request, response) => { keymanAppTestBotMiddleware(request, response); } );
368369

369370
export function sendWsAlert(hasChanged: boolean, message: string): boolean {
370371
if(hasChanged) {
@@ -459,7 +460,7 @@ app.get('/status/github-contributions', async (request, response) => {
459460
try {
460461
contributions = await githubContributionsService.get(sprintStartDateTime.toISOString());
461462
} catch(e) {
462-
console.debug(e);
463+
console.error(inspect(e));
463464
Sentry.addBreadcrumb({
464465
category: "Request",
465466
message: JSON.stringify(request.query)

server/keymanapp-test-bot/artifact-links-comment.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import teamcityService from "../services/teamcity/teamcity.js";
44
import { statusData } from '../data/status-data.js';
55
import { artifactLinks } from '../../shared/artifact-links.js';
66
import { getTeamcityUrlParams } from "../../shared/getTeamcityUrlParams.js";
7+
import { inspect } from "node:util";
78

89
type BuildDataCacheItem = {context:string, target_url:string, state:string};
910
type BuildDataCache = {[index:string]: BuildDataCacheItem};
@@ -22,7 +23,8 @@ export async function getArtifactLinksComment(
2223
try {
2324
statuses = await octokit.rest.repos.getCombinedStatusForRef({...data, ref: pull.data.head.ref});
2425
} catch(e) {
25-
console.error(`[@keymanapp-test-bot] ${e}`);
26+
console.error(`[@keymanapp-test-bot] getArtifactLinksComment: ${e}`);
27+
console.error(inspect(e));
2628
return '';
2729
}
2830
//const statuses = await octokit.rest.repos.getCombinedStatusForRef({owner:'keymanapp',repo:'keyman',ref:'fix/web/5950-clear-timeout-on-longpress-flick'/*pull.data.head.ref*/});
@@ -63,20 +65,21 @@ export async function getArtifactLinksComment(
6365
// artifactLinks
6466
let u;
6567
if(!s[context].target_url) {
66-
console.warn(`[@keymanapp-test-bot] skipping ${s[context].context}`);
68+
console.warn(`[@keymanapp-test-bot] getArtifactLinksComment: skipping ${s[context].context}`);
6769
continue;
6870
}
6971
try {
7072
u = new URL(s[context].target_url);
7173
} catch(e) {
72-
console.error(`[@keymanapp-test-bot] ${e}`);
74+
console.error(`[@keymanapp-test-bot] getArtifactLinksComment(2): ${e}`);
75+
console.error(inspect(e));
7376
continue;
7477
}
7578
if (context == 'Debian Packaging') {
7679
// https://github.com/keymanapp/keyman/actions/runs/4294449810
7780
const matches = s[context].target_url.match(/.+\/runs\/(\d+)/);
7881
if (!matches) {
79-
console.error(`[@keymanapp-test-bot] Can't find workflow run in url ${s[context].target_url}`);
82+
console.error(`[@keymanapp-test-bot] getArtifactLinksComment: Can't find workflow run in url ${s[context].target_url}`);
8083
return '';
8184
}
8285
const run_id = matches[1];
@@ -90,7 +93,7 @@ export async function getArtifactLinksComment(
9093
// "keyman-binarypkgs-focal_amd64"
9194
const distroMatches = artifact.name.match(/keyman-binarypkgs-(.+)_amd64/);
9295
if (!distroMatches) {
93-
console.error(`[@keymanapp-test-bot] Can't find distribution in artifact name ${artifact.name}`);
96+
console.error(`[@keymanapp-test-bot] getArtifactLinksComment: Can't find distribution in artifact name ${artifact.name}`);
9497
return '';
9598
}
9699
if (!links['Linux']) links['Linux'] = [];
@@ -102,12 +105,13 @@ export async function getArtifactLinksComment(
102105
});
103106
}
104107
} catch (e) {
105-
console.error(`[@keymanapp-test-bot] ${e}`);
108+
console.error(`[@keymanapp-test-bot] getArtifactLinksComment(3): ${e}`);
109+
console.error(inspect(e));
106110
return '';
107111
}
108112
} else if(u.searchParams.has('buildTypeId') || u.pathname.match(/\/buildConfiguration\//)) {
109113
const { buildTypeId, buildId } = getTeamcityUrlParams(u);
110-
console.log(`[@keymanapp-test-bot] Finding TeamCity build data for build ${buildTypeId}:${buildId}`)
114+
console.log(`[@keymanapp-test-bot] getArtifactLinksComment: Finding TeamCity build data for build ${buildTypeId}:${buildId}`)
111115

112116
version_with_tag = null;
113117
version = null;
@@ -116,7 +120,7 @@ export async function getArtifactLinksComment(
116120
if(buildData) version_with_tag = findBuildVersion(buildData);
117121
if(version_with_tag) version = /^(\d+\.\d+\.\d+)/.exec(version_with_tag)?.[1];
118122
if(!version) {
119-
console.error(`[@keymanapp-test-bot] Failed to find version information for artifact links for ${buildTypeId}:${buildId}; buildData: ${JSON.stringify(buildData)}`);
123+
console.error(`[@keymanapp-test-bot] getArtifactLinksComment: Failed to find version information for artifact links for ${buildTypeId}:${buildId}; buildData: ${JSON.stringify(buildData)}`);
120124
if(!teamCityDataFromCache) {
121125
continue;
122126
}
@@ -130,12 +134,12 @@ export async function getArtifactLinksComment(
130134
if(buildData) version_with_tag = findBuildVersion(buildData);
131135
if(version_with_tag) version = /^(\d+\.\d+\.\d+)/.exec(version_with_tag)?.[1];
132136
if(!version) {
133-
console.error(`[@keymanapp-test-bot] After reload, failed to find version information for artifact links for ${buildTypeId}:${buildId}; buildData: ${JSON.stringify(buildData)}`);
137+
console.error(`[@keymanapp-test-bot] getArtifactLinksComment: After reload, failed to find version information for artifact links for ${buildTypeId}:${buildId}; buildData: ${JSON.stringify(buildData)}`);
134138
continue;
135139
}
136140
}
137141

138-
console.log(`[@keymanapp-test-bot] Found version data for ${buildTypeId}:${buildId}:${version_with_tag}`)
142+
console.log(`[@keymanapp-test-bot] getArtifactLinksComment: Found version data for ${buildTypeId}:${buildId}:${version_with_tag}`)
139143

140144
const buildLevel = buildData?.properties?.property?.find(prop => prop.name == 'env.KEYMAN_BUILD_LEVEL')?.value;
141145
let t = artifactLinks.teamCityTargets[buildTypeId];

server/keymanapp-test-bot/issue-milestone.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ProbotOctokit } from "probot";
2-
import { Issue } from "@octokit/webhooks-types";
2+
import { components } from "@octokit/openapi-webhooks-types";
33

44
import { ProcessEventData } from "./keymanapp-test-bot.js";
55
import { getCurrentSprint } from "../current-sprint.js";
@@ -13,7 +13,7 @@ import { consoleError, consoleLog } from "../util/console-log.js";
1313
export async function updateIssueMilestoneWhenIssueClosed(
1414
octokit: InstanceType<typeof ProbotOctokit>,
1515
data: ProcessEventData,
16-
issue: Issue
16+
issue: components["schemas"]["webhook-issues-closed"]["issue"]
1717
): Promise<void> {
1818
consoleLog('pr-bot', null, `Updating issue #${issue.number} milestone`);
1919
const currentSprint = getCurrentSprint(statusData.cache.sprints?.current?.github?.data);

server/keymanapp-test-bot/keymanapp-test-bot-middleware.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { env } from "node:process";
88
import * as fs from 'node:fs';
99

10-
import { createNodeMiddleware, Probot } from 'probot';
10+
import { createNodeMiddleware, createProbot, Probot } from 'probot';
1111
import * as keymanappTestBot from './keymanapp-test-bot.js';
1212

1313
import { dirname } from 'node:path';
@@ -35,7 +35,7 @@ let privateKey, secret;
3535
if(fs.existsSync(privateKeyFilename))
3636
privateKey = fs.readFileSync(privateKeyFilename, 'utf8');
3737
else if(env.PROBOT_PRIVATE_KEY)
38-
privateKey = Buffer.from(env.PROBOT_PRIVATE_KEY, 'base64');
38+
privateKey = Buffer.from(env.PROBOT_PRIVATE_KEY, 'base64').toString('utf-8');
3939

4040
if(fs.existsSync(secretFilename))
4141
secret = fs.readFileSync(secretFilename, 'utf8').trim();
@@ -48,10 +48,14 @@ const probot = new Probot({
4848
secret: secret,
4949
});
5050

51-
const middleware = createNodeMiddleware(keymanappTestBot.default, { probot,
51+
const middleware = await createNodeMiddleware(keymanappTestBot.default, { probot,
5252
webhooksPath: "/",
5353
});
5454

5555
export default (req, res) => {
56-
return middleware(req, res);
56+
middleware(req, res, () => {
57+
res.writeHead(404);
58+
res.end();
59+
});
5760
};
61+

server/keymanapp-test-bot/keymanapp-test-bot.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @keymanapp-test-bot implementation
55
*/
66

7-
import { User } from "@octokit/webhooks-types";
7+
import { components } from "@octokit/openapi-webhooks-types";
88
import { Probot, ProbotOctokit } from "probot";
99
import { GetResponseTypeFromEndpointMethod, GetResponseDataTypeFromEndpointMethod } from "@octokit/types";
1010

@@ -33,7 +33,7 @@ export interface ProcessEventData {
3333
};
3434

3535
async function processEvent(
36-
octokit: InstanceType<typeof ProbotOctokit>,
36+
octokit: ProbotOctokit,
3737
data: ProcessEventData,
3838
is_pull_request: boolean
3939
) {
@@ -56,12 +56,12 @@ async function processEvent(
5656
}
5757

5858
async function processUserTest(
59-
octokit: InstanceType<typeof ProbotOctokit>,
59+
octokit: ProbotOctokit,
6060
data: ProcessEventData,
6161
is_pull_request: boolean,
6262
issue: GetResponseTypeFromEndpointMethod<typeof octokit.rest.issues.get>,
6363
pull: GetResponseTypeFromEndpointMethod<typeof octokit.rest.pulls.get>,
64-
issue_comments: GetResponseDataTypeFromEndpointMethod<typeof octokit.rest.issues.listComments>) {
64+
issue_comments: GetResponseDataTypeFromEndpointMethod<typeof octokit.rest.issues.listComments>): Promise<any> {
6565

6666
const mtp = new ManualTestParser();
6767
let protocol = new ManualTestProtocol(data.owner, data.repo, data.issue_number, is_pull_request, issue.data.id, pull?.data?.id);
@@ -147,9 +147,9 @@ async function processUserTest(
147147

148148
// If this is a pull request, add a status check
149149
if(is_pull_request) {
150-
let pr = await octokit.pulls.get({...data, pull_number: data.issue_number});
150+
let pr = await octokit.rest.pulls.get({...data, pull_number: data.issue_number});
151151

152-
let statusCounts = {}, totalTests = 0;
152+
let statusCounts: any = {}, totalTests = 0;
153153
statusCounts[ManualTestStatus.Open] = 0;
154154
statusCounts[ManualTestStatus.Passed] = 0;
155155
statusCounts[ManualTestStatus.Failed] = 0;
@@ -177,7 +177,7 @@ async function processUserTest(
177177
statusCounts[ManualTestStatus.Failed] + statusCounts[ManualTestStatus.Blocked] == 0 ? 'pending' : // no errors, but testing unfinished
178178
'failure'; // at least one error
179179

180-
await octokit.repos.createCommitStatus({...data,
180+
await octokit.rest.repos.createCommitStatus({...data,
181181
name: '@keymanapp-test-bot User Test Coverage',
182182
sha: pr.data.head.sha,
183183
state: state,
@@ -190,7 +190,7 @@ async function processUserTest(
190190
log('processEvent: EXIT');
191191
}
192192

193-
function shouldProcessEvent(sender: User, state: "closed"|"open"): boolean {
193+
function shouldProcessEvent(sender: components["schemas"]["simple-user"], state: "closed"|"open"): boolean {
194194
if(sender.type != "User")
195195
return false;
196196

@@ -206,7 +206,7 @@ function shouldProcessEvent(sender: User, state: "closed"|"open"): boolean {
206206
const exports = (app: Probot) => {
207207
app.on(['pull_request.edited', 'pull_request.opened', 'pull_request.synchronize'], (context) => {
208208
log('pull_request ENTER: '+context.id+', '+context.payload.pull_request.number);
209-
if(!shouldProcessEvent(context.payload.sender, context.payload.pull_request.state)) {
209+
if(!shouldProcessEvent(context.payload.sender!, context.payload.pull_request.state)) {
210210
log('pull_request EXIT: '+context.id+' -- skipping');
211211
return null;
212212
}
@@ -225,7 +225,7 @@ const exports = (app: Probot) => {
225225

226226
app.on(['issues.labeled'], (context) => {
227227
log('issues.labeled ENTER: '+context.id+', '+context.payload.issue.number);
228-
if(!shouldProcessEvent(context.payload.sender, context.payload.issue.state)) {
228+
if(!shouldProcessEvent(context.payload.sender, context.payload.issue.state!)) {
229229
log('issues.labeled EXIT: '+context.id+' -- skipping');
230230
return null;
231231
}
@@ -244,7 +244,7 @@ const exports = (app: Probot) => {
244244

245245
app.on(['issues.opened', 'issues.edited'], (context) => {
246246
log('issue ENTER: '+context.id+', '+context.payload.issue.number);
247-
if(!shouldProcessEvent(context.payload.sender, context.payload.issue.state)) {
247+
if(!shouldProcessEvent(context.payload.sender, context.payload.issue.state!)) {
248248
log('issue EXIT: '+context.id+' -- skipping');
249249
return null;
250250
}

server/keymanapp-test-bot/test-user-test-results-comment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import ManualTestParser from "../../shared/manual-test/manual-test-parser.js";
1616
import { ManualTestProtocol } from "../../shared/manual-test/manual-test-protocols.js";
1717
import { getArtifactLinksComment } from "./artifact-links-comment.js";
1818

19-
const pr = 6849;
19+
const pr = 16099;
2020
const is_pull_request = true;
2121
const data = {owner:'keymanapp', repo:'keyman', issue_number: pr};
2222

0 commit comments

Comments
 (0)