mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 13:17:08 +00:00
Tidy up
This commit is contained in:
parent
59e98f96c2
commit
b7f544dccd
@ -236,7 +236,6 @@ export class AdminRoom extends EventEmitter {
|
||||
},
|
||||
};
|
||||
});
|
||||
console.log(newData);
|
||||
if (newData.github?.notifications?.participating) {
|
||||
return this.sendNotice(`Filtering for events you are participating in`);
|
||||
}
|
||||
@ -470,7 +469,6 @@ export class AdminRoom extends EventEmitter {
|
||||
let newValue = false;
|
||||
await this.saveAccountData((data) => {
|
||||
const currentNotifs = (data.gitlab || {})[instanceName].notifications;
|
||||
console.log("current:", currentNotifs.enabled);
|
||||
newValue = !currentNotifs.enabled;
|
||||
return {
|
||||
...data,
|
||||
|
@ -6,6 +6,7 @@ import { Webhooks } from "../Webhooks";
|
||||
import { MatrixSender } from "../MatrixSender";
|
||||
import { UserNotificationWatcher } from "../Notifications/UserNotificationWatcher";
|
||||
|
||||
LogWrapper.configureLogging("debug");
|
||||
const log = new LogWrapper("App");
|
||||
|
||||
async function start() {
|
||||
|
@ -288,7 +288,7 @@ export class GitHubRepoConnection implements IConnection {
|
||||
}
|
||||
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);
|
||||
await this.as.botIntent.sendEvent(this.roomId, {
|
||||
msgtype: "m.notice",
|
||||
|
@ -6,6 +6,7 @@ import { MessageSenderClient } from "../MatrixSender"
|
||||
import { JiraIssueEvent } from "../Jira/WebhookTypes";
|
||||
import { FormatUtil } from "../FormatUtil";
|
||||
import markdownit from "markdown-it";
|
||||
import { generateWebLinkFromIssue } from "../Jira/Utils";
|
||||
|
||||
export interface JiraProjectConnectionState {
|
||||
id: string;
|
||||
@ -50,13 +51,13 @@ export class JiraProjectConnection implements IConnection {
|
||||
if (!creator) {
|
||||
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, {
|
||||
msgtype: "m.notice",
|
||||
body: content,
|
||||
formatted_body: md.renderInline(content),
|
||||
format: "org.matrix.custom.html",
|
||||
// TODO: Fix types.
|
||||
...FormatUtil.getPartialBodyForJiraIssue(data.issue)
|
||||
});
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import emoji from "node-emoji";
|
||||
// @ts-ignore
|
||||
import { contrastColor } from "contrast-color";
|
||||
import { JiraIssue } from './Jira/Types';
|
||||
import { generateWebLinkFromIssue } from './Jira/Utils';
|
||||
interface IMinimalRepository {
|
||||
id: number;
|
||||
full_name: string;
|
||||
@ -103,11 +104,18 @@ export class FormatUtil {
|
||||
}
|
||||
|
||||
public static getPartialBodyForJiraIssue(issue: JiraIssue) {
|
||||
const url = generateWebLinkFromIssue(issue);
|
||||
return {
|
||||
"external_url": issue.self,
|
||||
"external_url": url,
|
||||
"uk.half-shot.matrix-github.jira.issue": {
|
||||
id: issue.id,
|
||||
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,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -129,6 +129,7 @@ export class GithubBridge {
|
||||
this.messageClient,
|
||||
instance);
|
||||
}
|
||||
|
||||
if (JiraProjectConnection.EventTypes.includes(state.type)) {
|
||||
if (!this.config.jira) {
|
||||
throw Error('JIRA is not configured');
|
||||
@ -598,8 +599,10 @@ export class GithubBridge {
|
||||
});
|
||||
|
||||
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 connections = this.getConnectionsForJiraProject(projectId);
|
||||
console.log(data.issue.fields.project);
|
||||
|
||||
connections.forEach(async (c) => {
|
||||
try {
|
||||
|
6
src/Jira/Utils.ts
Normal file
6
src/Jira/Utils.ts
Normal 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}`
|
||||
}
|
@ -99,9 +99,6 @@ export class Webhooks extends EventEmitter {
|
||||
private onJiraPayload(body: IJiraWebhookEvent) {
|
||||
const webhookEvent = body.webhookEvent.replace("jira:", "");
|
||||
log.debug(`onJiraPayload ${webhookEvent}:`, body);
|
||||
if (webhookEvent === "issue_updated") {
|
||||
console.log((body as JiraIssueEvent).issue.fields);
|
||||
}
|
||||
return `jira.${webhookEvent}`;
|
||||
}
|
||||
|
||||
@ -122,7 +119,7 @@ export class Webhooks extends EventEmitter {
|
||||
}
|
||||
|
||||
private onPayload(req: Request, res: Response) {
|
||||
log.debug(`New webhook: ${req.url}`);
|
||||
log.info(`New webhook: ${req.url}`);
|
||||
try {
|
||||
let eventName: string|null = null;
|
||||
const body = req.body;
|
||||
|
Loading…
x
Reference in New Issue
Block a user