Skip to content

Commit 40a75fa

Browse files
committed
Rename project
1 parent c5541ed commit 40a75fa

29 files changed

+131
-596
lines changed

Cargo.lock

+1-503
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "matrix-github"
2+
name = "matrix-hookshot"
33
version = "0.1.0"
44
edition = "2021"
55

Dockerfile

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ RUN yarn build
1818
# Stage 1: The actual container
1919
FROM node:16
2020

21-
COPY --from=builder /src/lib/ /bin/matrix-github/
22-
COPY --from=builder /src/public/ /bin/matrix-github/public/
23-
COPY --from=builder /src/package.json /bin/matrix-github/
24-
COPY --from=builder /src/yarn.lock /bin/matrix-github/
25-
WORKDIR /bin/matrix-github
21+
COPY --from=builder /src/lib/ /bin/matrix-hookshot/
22+
COPY --from=builder /src/public/ /bin/matrix-hookshot/public/
23+
COPY --from=builder /src/package.json /bin/matrix-hookshot/
24+
COPY --from=builder /src/yarn.lock /bin/matrix-hookshot/
25+
WORKDIR /bin/matrix-hookshot
2626
RUN yarn --production
2727

2828
VOLUME /data
2929
EXPOSE 9993
3030
EXPOSE 7775
3131

32-
CMD ["node", "/bin/matrix-github/App/BridgeApp.js", "/data/config.yml", "/data/registration.yml"]
32+
CMD ["node", "/bin/matrix-hookshot/App/BridgeApp.js", "/data/config.yml", "/data/registration.yml"]

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
matrix-github
1+
matrix-hookshot
22
=============
33

4+
*Previously matrix-github*
5+
46
[![#github-bridge:half-shot.uk](https://img.shields.io/matrix/github-bridge:half-shot.uk.svg?server_fqdn=matrix.half-shot.uk&label=%23github-bridge:half-shot.uk&logo=matrix)](https://matrix.to/#/#github-bridge:half-shot.uk)
57

68

@@ -12,12 +14,12 @@ This bridge requires at least Node 12, and Rust installed. If you do not have ru
1214

1315
To set up the bridge, simply clone this repository.
1416

15-
` git clone [email protected]:Half-Shot/matrix-github.git`
17+
` git clone [email protected]:Half-Shot/matrix-hookshot.git`
1618

1719
then you will need to install the dependencies
1820

1921
```sh
20-
cd matrix-github
22+
cd matrix-hookshot
2123
yarn
2224
```
2325

docker-compose.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
environment:
1616
CFG_QUEUE_MONOLITHIC: "false"
1717
CFG_QUEUE_HOST: "redis"
18-
command: node /bin/matrix-github/App/GithubWebhookApp.js /data/config.yml /data/registration.yml
18+
command: node /bin/matrix-hookshot/App/GithubWebhookApp.js /data/config.yml /data/registration.yml
1919
sender:
2020
build:
2121
context: .
@@ -27,7 +27,7 @@ services:
2727
environment:
2828
CFG_QUEUE_MONOLITHIC: "false"
2929
CFG_QUEUE_HOST: "redis"
30-
command: node /bin/matrix-github/App/MatrixSenderApp.js /data/config.yml /data/registration.yml
30+
command: node /bin/matrix-hookshot/App/MatrixSenderApp.js /data/config.yml /data/registration.yml
3131
app:
3232
build:
3333
context: .
@@ -41,4 +41,4 @@ services:
4141
environment:
4242
CFG_QUEUE_MONOLITHIC: "false"
4343
CFG_QUEUE_HOST: "redis"
44-
command: node /bin/matrix-github/App/BridgeApp.js /data/config.yml /data/registration.yml
44+
command: node /bin/matrix-hookshot/App/BridgeApp.js /data/config.yml /data/registration.yml

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"name": "matrix-github",
2+
"name": "matrix-hookshot",
33
"version": "0.1.0",
44
"description": "A bridge that displays GitHub issues/PRs as rooms.",
55
"main": "lib/app.js",
6-
"repository": "https://github.com/Half-Shot/matrix-github",
6+
"repository": "https://github.com/Half-Shot/matrix-hookshot",
77
"author": "Half-Shot",
88
"license": "MIT",
99
"private": false,
1010
"napi": {
11-
"name": "matrix-github-rs"
11+
"name": "matrix-hookshot-rs"
1212
},
1313
"engines": {
1414
"node": ">=12"

registration.sample.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
id: matrix-github # This can be anything, but must be unique within your homeserver
1+
id: matrix-hookshot # This can be anything, but must be unique within your homeserver
22
as_token: aaaaaaaaaa # This again can be a random string
33
hs_token: aaaaaaaaaa # ..as can this
44
namespaces:

src/AdminRoom.ts

+27-13
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ type ProjectsListForUserResponseData = Endpoints["GET /users/{username}/projects
2626
const md = new markdown();
2727
const log = new LogWrapper('AdminRoom');
2828

29-
export const BRIDGE_ROOM_TYPE = "uk.half-shot.matrix-github.room";
30-
export const BRIDGE_NOTIF_TYPE = "uk.half-shot.matrix-github.notif_state";
31-
export const BRIDGE_GITLAB_NOTIF_TYPE = "uk.half-shot.matrix-github.gitlab.notif_state";
29+
export const LEGACY_BRIDGE_ROOM_TYPE = "uk.half-shot.matrix-github.room";
30+
export const LEGACY_BRIDGE_NOTIF_TYPE = "uk.half-shot.matrix-github.notif_state";
31+
export const LEGACY_BRIDGE_GITLAB_NOTIF_TYPE = "uk.half-shot.matrix-github.gitlab.notif_state";
3232

33+
export const BRIDGE_ROOM_TYPE = "uk.half-shot.matrix-hookshot.github.room";
34+
export const BRIDGE_NOTIF_TYPE = "uk.half-shot.matrix-hookshot.github.notif_state";
35+
export const BRIDGE_GITLAB_NOTIF_TYPE = "uk.half-shot.matrix-hookshot.gitlab.notif_state";
3336
export interface AdminAccountData {
3437
// eslint-disable-next-line camelcase
3538
admin_user: string;
@@ -109,19 +112,29 @@ export class AdminRoom extends EventEmitter {
109112
public async getNotifSince(type: "github"|"gitlab", instanceName?: string) {
110113
if (type === "gitlab") {
111114
try {
112-
const { since } = await this.botIntent.underlyingClient.getRoomAccountData(
113-
`${BRIDGE_GITLAB_NOTIF_TYPE}:${instanceName}`, this.roomId
115+
let accountData: null|{since: number} = await this.botIntent.underlyingClient.getSafeRoomAccountData(
116+
`${BRIDGE_GITLAB_NOTIF_TYPE}:${instanceName}`, this.roomId, null
114117
);
115-
return since;
118+
if (!accountData) {
119+
accountData = await this.botIntent.underlyingClient.getSafeRoomAccountData(
120+
`${LEGACY_BRIDGE_GITLAB_NOTIF_TYPE}:${instanceName}`, this.roomId, { since: 0 }
121+
);
122+
}
123+
return accountData.since;
116124
} catch {
117125
// TODO: We should look at this error.
118126
return 0;
119127
}
120128
}
121129
try {
122-
const { since } = await this.botIntent.underlyingClient.getRoomAccountData(BRIDGE_NOTIF_TYPE, this.roomId);
123-
log.debug(`Got ${type} notif-since to ${since}`);
124-
return since;
130+
let accountData: null|{since: number} = await this.botIntent.underlyingClient.getSafeRoomAccountData(BRIDGE_NOTIF_TYPE, this.roomId, { since: 0 });
131+
if (!accountData) {
132+
accountData = await this.botIntent.underlyingClient.getSafeRoomAccountData(
133+
`${LEGACY_BRIDGE_NOTIF_TYPE}:${instanceName}`, this.roomId, { since: 0 }
134+
);
135+
}
136+
log.debug(`Got ${type} notif-since to ${accountData.since}`);
137+
return accountData.since;
125138
} catch (ex) {
126139
log.warn(`Filed to get ${type} notif-since`, ex);
127140
// TODO: We should look at this error.
@@ -506,7 +519,7 @@ export class AdminRoom extends EventEmitter {
506519
const users = parameters.filter(param => param.toLowerCase().startsWith("users:")).map(param => param.toLowerCase().substring("users:".length).split(",")).flat();
507520
const repos = parameters.filter(param => param.toLowerCase().startsWith("repos:")).map(param => param.toLowerCase().substring("repos:".length).split(",")).flat();
508521
if (orgs.length + users.length + repos.length === 0) {
509-
return this.sendNotice("You must specify some filter options like 'orgs:matrix-org,half-shot', 'users:Half-Shot' or 'repos:matrix-github'");
522+
return this.sendNotice("You must specify some filter options like 'orgs:matrix-org,half-shot', 'users:Half-Shot' or 'repos:matrix-hookshot'");
510523
}
511524
this.notifFilter.setFilter(name, {
512525
orgs,
@@ -533,9 +546,10 @@ export class AdminRoom extends EventEmitter {
533546
}
534547

535548
private async saveAccountData(updateFn: (record: AdminAccountData) => AdminAccountData) {
536-
const oldData: AdminAccountData = await this.botIntent.underlyingClient.getRoomAccountData(
537-
BRIDGE_ROOM_TYPE, this.roomId,
538-
);
549+
let oldData: AdminAccountData|null = await this.botIntent.underlyingClient.getSafeRoomAccountData(BRIDGE_ROOM_TYPE, this.roomId, null);
550+
if (!oldData) {
551+
oldData = await this.botIntent.underlyingClient.getSafeRoomAccountData(LEGACY_BRIDGE_ROOM_TYPE, this.roomId, {admin_user: this.userId});
552+
}
539553
const newData = updateFn(oldData);
540554
await this.botIntent.underlyingClient.setRoomAccountData(BRIDGE_ROOM_TYPE, this.roomId, newData);
541555
this.emit("settings.changed", this, oldData, newData);

src/CommentProcessor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const log = new LogWrapper("CommentProcessor");
1818
interface IMatrixCommentEvent extends MatrixMessageContent {
1919
// eslint-disable-next-line camelcase
2020
external_url: string;
21-
"uk.half-shot.matrix-github.comment": {
21+
"uk.half-shot.matrix-hookshot.github.comment": {
2222
id: number;
2323
};
2424
}

src/Connections/GenericHook.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ const TRANSFORMATION_TIMEOUT_MS = 2000;
1919
* Handles rooms connected to a github repo.
2020
*/
2121
export class GenericHookConnection implements IConnection {
22-
static readonly CanonicalEventType = "uk.half-shot.matrix-github.generic.hook";
22+
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.generic.hook";
23+
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.generic.hook";
2324

2425
static readonly EventTypes = [
2526
GenericHookConnection.CanonicalEventType,
27+
GenericHookConnection.LegacyCanonicalEventType,
2628
];
2729

2830
public get hookId() {

src/Connections/GithubDiscussion.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ const md = new markdown();
2727
* Handles rooms connected to a github repo.
2828
*/
2929
export class GitHubDiscussionConnection implements IConnection {
30-
static readonly CanonicalEventType = "uk.half-shot.matrix-github.discussion";
30+
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.discussion";
31+
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.discussion";
3132

3233
static readonly EventTypes = [
33-
GitHubDiscussionConnection.CanonicalEventType, // Legacy event, with an awful name.
34+
GitHubDiscussionConnection.CanonicalEventType,
35+
GitHubDiscussionConnection.LegacyCanonicalEventType,
3436
];
3537

3638
static readonly QueryRoomRegex = /#github_disc_(.+)_(.+)_(\d+):.*/;
@@ -131,7 +133,7 @@ export class GitHubDiscussionConnection implements IConnection {
131133
formatted_body: md.render(data.comment.body),
132134
msgtype: 'm.text',
133135
external_url: data.comment.html_url,
134-
'uk.half-shot.matrix-github.discussion.comment_id': data.comment.id,
136+
'uk.half-shot.matrix-hookshot.github.discussion.comment_id': data.comment.id,
135137
});
136138
}
137139
}

src/Connections/GithubDiscussionSpace.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ export interface GitHubDiscussionSpaceConnectionState {
1717
* Handles rooms connected to a github repo.
1818
*/
1919
export class GitHubDiscussionSpace implements IConnection {
20-
static readonly CanonicalEventType = "uk.half-shot.matrix-github.discussion.space";
20+
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.discussion.space";
21+
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.discussion.space";
2122

2223
static readonly EventTypes = [
23-
GitHubDiscussionSpace.CanonicalEventType, // Legacy event, with an awful name.
24+
GitHubDiscussionSpace.CanonicalEventType,
25+
GitHubDiscussionSpace.LegacyCanonicalEventType,
2426
];
2527

2628
static readonly QueryRoomRegex = /#github_disc_(.+)_(.+):.*/;
@@ -64,9 +66,6 @@ export class GitHubDiscussionSpace implements IConnection {
6466
responseType: 'arraybuffer',
6567
});
6668
log.info(`uploading ${profile.data.avatar_url}`);
67-
// This does exist, but headers is silly and doesn't have content-type.
68-
// tslint:disable-next-line: no-any
69-
console.log(res.headers);
7069
const contentType: string = res.headers["content-type"];
7170
const mxcUrl = await opts.as.botClient.uploadContent(
7271
Buffer.from(res.data as ArrayBuffer),

src/Connections/GithubIssue.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ interface IQueryRoomOpts {
3838
* Handles rooms connected to a github repo.
3939
*/
4040
export class GitHubIssueConnection implements IConnection {
41-
static readonly CanonicalEventType = "uk.half-shot.matrix-github.bridge";
41+
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.issue";
42+
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.bridge";
4243

4344
static readonly EventTypes = [
44-
GitHubIssueConnection.CanonicalEventType, // Legacy event, with an awful name.
45+
GitHubIssueConnection.CanonicalEventType,
46+
GitHubIssueConnection.LegacyCanonicalEventType,
4547
];
4648

4749
static readonly QueryRoomRegex = /#github_(.+)_(.+)_(\d+):.*/;
@@ -84,9 +86,6 @@ export class GitHubIssueConnection implements IConnection {
8486
responseType: 'arraybuffer',
8587
});
8688
log.info(`uploading ${profile.data.avatar_url}`);
87-
// This does exist, but headers is silly and doesn't have content-type.
88-
// tslint:disable-next-line: no-any
89-
console.log(res.headers);
9089
const contentType: string = res.headers["content-type"];
9190
const mxcUrl = await opts.as.botClient.uploadContent(
9291
Buffer.from(res.data as ArrayBuffer),

src/Connections/GithubProject.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ const log = new LogWrapper("GitHubProjectConnection");
1414
* Handles rooms connected to a github repo.
1515
*/
1616
export class GitHubProjectConnection implements IConnection {
17-
static readonly CanonicalEventType = "uk.half-shot.matrix-github.project";
17+
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.project";
18+
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.project";
1819

1920
static readonly EventTypes = [
20-
GitHubProjectConnection.CanonicalEventType, // Legacy event, with an awful name.
21+
GitHubProjectConnection.CanonicalEventType,
22+
GitHubProjectConnection.LegacyCanonicalEventType,
2123
];
2224

2325
static async onOpenProject(project: ProjectsGetResponseData, as: Appservice, inviteUser: string): Promise<GitHubProjectConnection> {

src/Connections/GithubRepo.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ function compareEmojiStrings(e0: string, e1: string, e0Index = 0) {
5858
* Handles rooms connected to a github repo.
5959
*/
6060
export class GitHubRepoConnection implements IConnection {
61-
static readonly CanonicalEventType = "uk.half-shot.matrix-github.repository";
61+
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.repository";
62+
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.repository";
6263

6364
static readonly EventTypes = [
64-
GitHubRepoConnection.CanonicalEventType, // Legacy event, with an awful name.
65+
GitHubRepoConnection.CanonicalEventType,
66+
GitHubRepoConnection.LegacyCanonicalEventType,
6567
];
6668

6769
static readonly QueryRoomRegex = /#github_(.+)_(.+):.*/;
@@ -101,9 +103,6 @@ export class GitHubRepoConnection implements IConnection {
101103
responseType: 'arraybuffer',
102104
});
103105
log.info(`uploading ${profile.data.avatar_url}`);
104-
// This does exist, but headers is silly and doesn't have content-type.
105-
// tslint:disable-next-line: no-any
106-
console.log(res.headers);
107106
const contentType: string = res.headers["content-type"];
108107
const mxcUrl = await opts.as.botClient.uploadContent(
109108
Buffer.from(res.data as ArrayBuffer),
@@ -481,7 +480,7 @@ ${event.release.body}`;
481480
// eslint-disable-next-line camelcase
482481
const {event_id, key} = (evt.content as MatrixReactionContent)["m.relates_to"];
483482
const ev = await this.as.botClient.getEvent(this.roomId, event_id);
484-
const issueContent = ev.content["uk.half-shot.matrix-github.issue"];
483+
const issueContent = ev.content["uk.half-shot.matrix-hookshot.github.issue"];
485484
if (!issueContent) {
486485
log.debug('Reaction to event did not pertain to a issue');
487486
return; // Not our event.

src/Connections/GithubUserSpace.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export interface GitHubUserSpaceConnectionState {
1616
* Handles rooms connected to a github repo.
1717
*/
1818
export class GitHubUserSpace implements IConnection {
19-
static readonly CanonicalEventType = "uk.half-shot.matrix-github.user.space";
19+
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.user.space";
20+
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.user.space";
2021

2122
static readonly EventTypes = [
2223
GitHubUserSpace.CanonicalEventType, // Legacy event, with an awful name.

src/Connections/GitlabIssue.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ const log = new LogWrapper("GitLabIssueConnection");
3333
* Handles rooms connected to a github repo.
3434
*/
3535
export class GitLabIssueConnection implements IConnection {
36-
static readonly CanonicalEventType = "uk.half-shot.matrix-github.gitlab.issue";
36+
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.gitlab.issue";
37+
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.gitlab.issue";
3738

3839
static readonly EventTypes = [
3940
GitLabIssueConnection.CanonicalEventType,
41+
GitLabIssueConnection.LegacyCanonicalEventType,
4042
];
4143

4244
static readonly QueryRoomRegex = /#gitlab_(.+)_(.+)_(\d+):.*/;
@@ -104,7 +106,6 @@ export class GitLabIssueConnection implements IConnection {
104106

105107
public async onCommentCreated(event: IGitLabWebhookNoteEvent) {
106108
log.info(`${this.toString()} onCommentCreated ${event.object_attributes.noteable_id}`);
107-
console.log(event);
108109
if (event.repository) {
109110
// Delay to stop comments racing sends
110111
await new Promise((resolve) => setTimeout(resolve, 500));

src/Connections/GitlabRepo.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ const md = new markdown();
2323
* Handles rooms connected to a github repo.
2424
*/
2525
export class GitLabRepoConnection implements IConnection {
26-
static readonly CanonicalEventType = "uk.half-shot.matrix-github.gitlab.repository";
26+
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.gitlab.repository";
27+
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.gitlab.repository";
2728

2829
static readonly EventTypes = [
29-
GitLabRepoConnection.CanonicalEventType, // Legacy event, with an awful name.
30+
GitLabRepoConnection.CanonicalEventType,
31+
GitLabRepoConnection.LegacyCanonicalEventType,
3032
];
3133

3234
static botCommands: BotCommands;

src/Connections/JiraProject.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ const md = new markdownit();
2222
* Handles rooms connected to a github repo.
2323
*/
2424
export class JiraProjectConnection implements IConnection {
25-
static readonly CanonicalEventType = "uk.half-shot.matrix-github.jira.project";
25+
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.jira.project";
26+
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.jira.project";
2627

2728
static readonly EventTypes = [
2829
JiraProjectConnection.CanonicalEventType,
30+
JiraProjectConnection.LegacyCanonicalEventType,
2931
];
3032

3133
static getTopicString(authorName: string, state: string) {

src/FormatUtil.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn get_partial_body_for_jira_issue(ctx: CallContext) -> Result<JsObject, Nap
152152
.create_string_from_std(jira_issue.fields.project._self)?,
153153
)?;
154154

155-
body.set_named_property("uk.half-shot.matrix-github.jira.issue", jira_issue_result)?;
156-
body.set_named_property("uk.half-shot.matrix-github.jira.project", jira_project)?;
155+
body.set_named_property("uk.half-shot.matrix-hookshot.jira.issue", jira_issue_result)?;
156+
body.set_named_property("uk.half-shot.matrix-hookshot.jira.project", jira_project)?;
157157
Ok(body)
158158
}

0 commit comments

Comments
 (0)