This commit is contained in:
Will Hunt 2021-11-12 16:55:16 +00:00
parent 59e98f96c2
commit b7f544dccd
8 changed files with 24 additions and 10 deletions

View File

@ -236,7 +236,6 @@ export class AdminRoom extends EventEmitter {
}, },
}; };
}); });
console.log(newData);
if (newData.github?.notifications?.participating) { if (newData.github?.notifications?.participating) {
return this.sendNotice(`Filtering for events you are participating in`); return this.sendNotice(`Filtering for events you are participating in`);
} }
@ -470,7 +469,6 @@ export class AdminRoom extends EventEmitter {
let newValue = false; let newValue = false;
await this.saveAccountData((data) => { await this.saveAccountData((data) => {
const currentNotifs = (data.gitlab || {})[instanceName].notifications; const currentNotifs = (data.gitlab || {})[instanceName].notifications;
console.log("current:", currentNotifs.enabled);
newValue = !currentNotifs.enabled; newValue = !currentNotifs.enabled;
return { return {
...data, ...data,

View File

@ -6,6 +6,7 @@ import { Webhooks } from "../Webhooks";
import { MatrixSender } from "../MatrixSender"; import { MatrixSender } from "../MatrixSender";
import { UserNotificationWatcher } from "../Notifications/UserNotificationWatcher"; import { UserNotificationWatcher } from "../Notifications/UserNotificationWatcher";
LogWrapper.configureLogging("debug");
const log = new LogWrapper("App"); const log = new LogWrapper("App");
async function start() { async function start() {

View File

@ -288,7 +288,7 @@ export class GitHubRepoConnection implements IConnection {
} }
const orgRepoName = event.repository.full_name; const orgRepoName = event.repository.full_name;
const content = emoji.emojify(`${event.issue.user?.login} created new issue [${orgRepoName}#${event.issue.number}](${event.issue.html_url}): "${event.issue.title}"`); const content = emoji.emojify(`${event.issue.user?.login} created a new JIRA issue [${orgRepoName}#${event.issue.number}](${event.issue}): "${event.issue.title}"`);
const { labelsHtml, labelsStr } = FormatUtil.formatLabels(event.issue.labels); const { labelsHtml, labelsStr } = FormatUtil.formatLabels(event.issue.labels);
await this.as.botIntent.sendEvent(this.roomId, { await this.as.botIntent.sendEvent(this.roomId, {
msgtype: "m.notice", msgtype: "m.notice",

View File

@ -6,6 +6,7 @@ import { MessageSenderClient } from "../MatrixSender"
import { JiraIssueEvent } from "../Jira/WebhookTypes"; import { JiraIssueEvent } from "../Jira/WebhookTypes";
import { FormatUtil } from "../FormatUtil"; import { FormatUtil } from "../FormatUtil";
import markdownit from "markdown-it"; import markdownit from "markdown-it";
import { generateWebLinkFromIssue } from "../Jira/Utils";
export interface JiraProjectConnectionState { export interface JiraProjectConnectionState {
id: string; id: string;
@ -50,13 +51,13 @@ export class JiraProjectConnection implements IConnection {
if (!creator) { if (!creator) {
throw Error('No creator field'); throw Error('No creator field');
} }
const content = `${creator.displayName} created new issue [${data.issue.key}](${data.issue.self}): "${data.issue.fields.summary}"`; const url = generateWebLinkFromIssue(data.issue);
const content = `${creator.displayName} created a new JIRA issue [${data.issue.key}](${url}): "${data.issue.fields.summary}"`;
await this.as.botIntent.sendEvent(this.roomId, { await this.as.botIntent.sendEvent(this.roomId, {
msgtype: "m.notice", msgtype: "m.notice",
body: content, body: content,
formatted_body: md.renderInline(content), formatted_body: md.renderInline(content),
format: "org.matrix.custom.html", format: "org.matrix.custom.html",
// TODO: Fix types.
...FormatUtil.getPartialBodyForJiraIssue(data.issue) ...FormatUtil.getPartialBodyForJiraIssue(data.issue)
}); });
} }

View File

@ -4,6 +4,7 @@ import emoji from "node-emoji";
// @ts-ignore // @ts-ignore
import { contrastColor } from "contrast-color"; import { contrastColor } from "contrast-color";
import { JiraIssue } from './Jira/Types'; import { JiraIssue } from './Jira/Types';
import { generateWebLinkFromIssue } from './Jira/Utils';
interface IMinimalRepository { interface IMinimalRepository {
id: number; id: number;
full_name: string; full_name: string;
@ -103,11 +104,18 @@ export class FormatUtil {
} }
public static getPartialBodyForJiraIssue(issue: JiraIssue) { public static getPartialBodyForJiraIssue(issue: JiraIssue) {
const url = generateWebLinkFromIssue(issue);
return { return {
"external_url": issue.self, "external_url": url,
"uk.half-shot.matrix-github.jira.issue": { "uk.half-shot.matrix-github.jira.issue": {
id: issue.id, id: issue.id,
key: issue.key, key: issue.key,
api_url: issue.self,
},
"uk.half-shot.matrix-github.jira.project": {
id: issue.fields.project.id,
key: issue.fields.project.key,
api_url: issue.fields.project.self,
}, },
}; };
} }

View File

@ -129,6 +129,7 @@ export class GithubBridge {
this.messageClient, this.messageClient,
instance); instance);
} }
if (JiraProjectConnection.EventTypes.includes(state.type)) { if (JiraProjectConnection.EventTypes.includes(state.type)) {
if (!this.config.jira) { if (!this.config.jira) {
throw Error('JIRA is not configured'); throw Error('JIRA is not configured');
@ -598,8 +599,10 @@ export class GithubBridge {
}); });
this.queue.on<JiraIssueEvent>("jira.issue_created", async ({data}) => { this.queue.on<JiraIssueEvent>("jira.issue_created", async ({data}) => {
log.info(`JIRA issue created for project ${data.issue.fields.project.id}, issue id ${data.issue.id}`);
const projectId = data.issue.fields.project.id; const projectId = data.issue.fields.project.id;
const connections = this.getConnectionsForJiraProject(projectId); const connections = this.getConnectionsForJiraProject(projectId);
console.log(data.issue.fields.project);
connections.forEach(async (c) => { connections.forEach(async (c) => {
try { try {

6
src/Jira/Utils.ts Normal file
View File

@ -0,0 +1,6 @@
import { JiraIssue } from "./Types";
export function generateWebLinkFromIssue(issue: JiraIssue) {
const { origin } = new URL(issue.self);
return `${origin}/browse/${issue.key}`
}

View File

@ -99,9 +99,6 @@ export class Webhooks extends EventEmitter {
private onJiraPayload(body: IJiraWebhookEvent) { private onJiraPayload(body: IJiraWebhookEvent) {
const webhookEvent = body.webhookEvent.replace("jira:", ""); const webhookEvent = body.webhookEvent.replace("jira:", "");
log.debug(`onJiraPayload ${webhookEvent}:`, body); log.debug(`onJiraPayload ${webhookEvent}:`, body);
if (webhookEvent === "issue_updated") {
console.log((body as JiraIssueEvent).issue.fields);
}
return `jira.${webhookEvent}`; return `jira.${webhookEvent}`;
} }
@ -122,7 +119,7 @@ export class Webhooks extends EventEmitter {
} }
private onPayload(req: Request, res: Response) { private onPayload(req: Request, res: Response) {
log.debug(`New webhook: ${req.url}`); log.info(`New webhook: ${req.url}`);
try { try {
let eventName: string|null = null; let eventName: string|null = null;
const body = req.body; const body = req.body;