Skip to content
Draft
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
2 changes: 1 addition & 1 deletion server/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ app.post('/webhook/discourse', (request, response) => {
response.send('ok');
});

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

function sendWsAlert(hasChanged: boolean, message: string): boolean {
if(hasChanged) {
Expand Down
4 changes: 2 additions & 2 deletions server/keymanapp-test-bot/issue-milestone.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProbotOctokit } from "probot";
import { Issue } from "@octokit/webhooks-types";
import { components } from "@octokit/openapi-webhooks-types";

import { ProcessEventData } from "./keymanapp-test-bot.js";
import { getCurrentSprint } from "../current-sprint.js";
Expand All @@ -13,7 +13,7 @@ import { consoleError, consoleLog } from "../util/console-log.js";
export async function updateIssueMilestoneWhenIssueClosed(
octokit: InstanceType<typeof ProbotOctokit>,
data: ProcessEventData,
issue: Issue
issue: components["schemas"]["webhook-issues-closed"]["issue"]
): Promise<void> {
consoleLog('pr-bot', null, `Updating issue #${issue.number} milestone`);
const currentSprint = getCurrentSprint(statusData.cache.sprints?.current?.github?.data);
Expand Down
20 changes: 16 additions & 4 deletions server/keymanapp-test-bot/keymanapp-test-bot-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { env } from "node:process";
import * as fs from 'node:fs';

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

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

if(fs.existsSync(secretFilename))
secret = fs.readFileSync(secretFilename, 'utf8').trim();
Expand All @@ -48,10 +48,22 @@ const probot = new Probot({
secret: secret,
});

const middleware = createNodeMiddleware(keymanappTestBot.default, { probot,
// const probot = createProbot({
// env: {
// APP_ID: appId.toString(),
// PRIVATE_KEY: privateKey,
// WEBHOOK_SECRET: secret,
// }
// });
Comment on lines +51 to +57
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets uncommented for deployment?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sadly this whole PR should probably be brought back to draft because I am very much lacking in confidence that the update to probot 14.x is actually correct. I need to test it locally, which is kinda a hassle to setup (still want to split testbot out of status site at some point, too)


const middleware = await createNodeMiddleware(keymanappTestBot.default, { probot,
webhooksPath: "/",
});

export default (req, res) => {
return middleware(req, res);
middleware(req, res, () => {
res.writeHead(404);
res.end();
});
};

22 changes: 11 additions & 11 deletions server/keymanapp-test-bot/keymanapp-test-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @keymanapp-test-bot implementation
*/

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

Expand Down Expand Up @@ -33,7 +33,7 @@ export interface ProcessEventData {
};

async function processEvent(
octokit: InstanceType<typeof ProbotOctokit>,
octokit: ProbotOctokit,
data: ProcessEventData,
is_pull_request: boolean
) {
Expand All @@ -56,12 +56,12 @@ async function processEvent(
}

async function processUserTest(
octokit: InstanceType<typeof ProbotOctokit>,
octokit: ProbotOctokit,
data: ProcessEventData,
is_pull_request: boolean,
issue: GetResponseTypeFromEndpointMethod<typeof octokit.rest.issues.get>,
pull: GetResponseTypeFromEndpointMethod<typeof octokit.rest.pulls.get>,
issue_comments: GetResponseDataTypeFromEndpointMethod<typeof octokit.rest.issues.listComments>) {
issue_comments: GetResponseDataTypeFromEndpointMethod<typeof octokit.rest.issues.listComments>): Promise<any> {

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

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

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

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

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

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

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

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