Skip to content

Commit

Permalink
Rename project
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Nov 22, 2021
1 parent c5541ed commit 40a75fa
Show file tree
Hide file tree
Showing 29 changed files with 131 additions and 596 deletions.
504 changes: 1 addition & 503 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "matrix-github"
name = "matrix-hookshot"
version = "0.1.0"
edition = "2021"

Expand Down
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ RUN yarn build
# Stage 1: The actual container
FROM node:16

COPY --from=builder /src/lib/ /bin/matrix-github/
COPY --from=builder /src/public/ /bin/matrix-github/public/
COPY --from=builder /src/package.json /bin/matrix-github/
COPY --from=builder /src/yarn.lock /bin/matrix-github/
WORKDIR /bin/matrix-github
COPY --from=builder /src/lib/ /bin/matrix-hookshot/
COPY --from=builder /src/public/ /bin/matrix-hookshot/public/
COPY --from=builder /src/package.json /bin/matrix-hookshot/
COPY --from=builder /src/yarn.lock /bin/matrix-hookshot/
WORKDIR /bin/matrix-hookshot
RUN yarn --production

VOLUME /data
EXPOSE 9993
EXPOSE 7775

CMD ["node", "/bin/matrix-github/App/BridgeApp.js", "/data/config.yml", "/data/registration.yml"]
CMD ["node", "/bin/matrix-hookshot/App/BridgeApp.js", "/data/config.yml", "/data/registration.yml"]
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
matrix-github
matrix-hookshot
=============

*Previously matrix-github*

[![#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)


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

To set up the bridge, simply clone this repository.

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

then you will need to install the dependencies

```sh
cd matrix-github
cd matrix-hookshot
yarn
```

Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
environment:
CFG_QUEUE_MONOLITHIC: "false"
CFG_QUEUE_HOST: "redis"
command: node /bin/matrix-github/App/GithubWebhookApp.js /data/config.yml /data/registration.yml
command: node /bin/matrix-hookshot/App/GithubWebhookApp.js /data/config.yml /data/registration.yml
sender:
build:
context: .
Expand All @@ -27,7 +27,7 @@ services:
environment:
CFG_QUEUE_MONOLITHIC: "false"
CFG_QUEUE_HOST: "redis"
command: node /bin/matrix-github/App/MatrixSenderApp.js /data/config.yml /data/registration.yml
command: node /bin/matrix-hookshot/App/MatrixSenderApp.js /data/config.yml /data/registration.yml
app:
build:
context: .
Expand All @@ -41,4 +41,4 @@ services:
environment:
CFG_QUEUE_MONOLITHIC: "false"
CFG_QUEUE_HOST: "redis"
command: node /bin/matrix-github/App/BridgeApp.js /data/config.yml /data/registration.yml
command: node /bin/matrix-hookshot/App/BridgeApp.js /data/config.yml /data/registration.yml
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "matrix-github",
"name": "matrix-hookshot",
"version": "0.1.0",
"description": "A bridge that displays GitHub issues/PRs as rooms.",
"main": "lib/app.js",
"repository": "https://github.com/Half-Shot/matrix-github",
"repository": "https://github.com/Half-Shot/matrix-hookshot",
"author": "Half-Shot",
"license": "MIT",
"private": false,
"napi": {
"name": "matrix-github-rs"
"name": "matrix-hookshot-rs"
},
"engines": {
"node": ">=12"
Expand Down
2 changes: 1 addition & 1 deletion registration.sample.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
id: matrix-github # This can be anything, but must be unique within your homeserver
id: matrix-hookshot # This can be anything, but must be unique within your homeserver
as_token: aaaaaaaaaa # This again can be a random string
hs_token: aaaaaaaaaa # ..as can this
namespaces:
Expand Down
40 changes: 27 additions & 13 deletions src/AdminRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ type ProjectsListForUserResponseData = Endpoints["GET /users/{username}/projects
const md = new markdown();
const log = new LogWrapper('AdminRoom');

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

export const BRIDGE_ROOM_TYPE = "uk.half-shot.matrix-hookshot.github.room";
export const BRIDGE_NOTIF_TYPE = "uk.half-shot.matrix-hookshot.github.notif_state";
export const BRIDGE_GITLAB_NOTIF_TYPE = "uk.half-shot.matrix-hookshot.gitlab.notif_state";
export interface AdminAccountData {
// eslint-disable-next-line camelcase
admin_user: string;
Expand Down Expand Up @@ -109,19 +112,29 @@ export class AdminRoom extends EventEmitter {
public async getNotifSince(type: "github"|"gitlab", instanceName?: string) {
if (type === "gitlab") {
try {
const { since } = await this.botIntent.underlyingClient.getRoomAccountData(
`${BRIDGE_GITLAB_NOTIF_TYPE}:${instanceName}`, this.roomId
let accountData: null|{since: number} = await this.botIntent.underlyingClient.getSafeRoomAccountData(
`${BRIDGE_GITLAB_NOTIF_TYPE}:${instanceName}`, this.roomId, null
);
return since;
if (!accountData) {
accountData = await this.botIntent.underlyingClient.getSafeRoomAccountData(
`${LEGACY_BRIDGE_GITLAB_NOTIF_TYPE}:${instanceName}`, this.roomId, { since: 0 }
);
}
return accountData.since;
} catch {
// TODO: We should look at this error.
return 0;
}
}
try {
const { since } = await this.botIntent.underlyingClient.getRoomAccountData(BRIDGE_NOTIF_TYPE, this.roomId);
log.debug(`Got ${type} notif-since to ${since}`);
return since;
let accountData: null|{since: number} = await this.botIntent.underlyingClient.getSafeRoomAccountData(BRIDGE_NOTIF_TYPE, this.roomId, { since: 0 });
if (!accountData) {
accountData = await this.botIntent.underlyingClient.getSafeRoomAccountData(
`${LEGACY_BRIDGE_NOTIF_TYPE}:${instanceName}`, this.roomId, { since: 0 }
);
}
log.debug(`Got ${type} notif-since to ${accountData.since}`);
return accountData.since;
} catch (ex) {
log.warn(`Filed to get ${type} notif-since`, ex);
// TODO: We should look at this error.
Expand Down Expand Up @@ -506,7 +519,7 @@ export class AdminRoom extends EventEmitter {
const users = parameters.filter(param => param.toLowerCase().startsWith("users:")).map(param => param.toLowerCase().substring("users:".length).split(",")).flat();
const repos = parameters.filter(param => param.toLowerCase().startsWith("repos:")).map(param => param.toLowerCase().substring("repos:".length).split(",")).flat();
if (orgs.length + users.length + repos.length === 0) {
return this.sendNotice("You must specify some filter options like 'orgs:matrix-org,half-shot', 'users:Half-Shot' or 'repos:matrix-github'");
return this.sendNotice("You must specify some filter options like 'orgs:matrix-org,half-shot', 'users:Half-Shot' or 'repos:matrix-hookshot'");
}
this.notifFilter.setFilter(name, {
orgs,
Expand All @@ -533,9 +546,10 @@ export class AdminRoom extends EventEmitter {
}

private async saveAccountData(updateFn: (record: AdminAccountData) => AdminAccountData) {
const oldData: AdminAccountData = await this.botIntent.underlyingClient.getRoomAccountData(
BRIDGE_ROOM_TYPE, this.roomId,
);
let oldData: AdminAccountData|null = await this.botIntent.underlyingClient.getSafeRoomAccountData(BRIDGE_ROOM_TYPE, this.roomId, null);
if (!oldData) {
oldData = await this.botIntent.underlyingClient.getSafeRoomAccountData(LEGACY_BRIDGE_ROOM_TYPE, this.roomId, {admin_user: this.userId});
}
const newData = updateFn(oldData);
await this.botIntent.underlyingClient.setRoomAccountData(BRIDGE_ROOM_TYPE, this.roomId, newData);
this.emit("settings.changed", this, oldData, newData);
Expand Down
2 changes: 1 addition & 1 deletion src/CommentProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const log = new LogWrapper("CommentProcessor");
interface IMatrixCommentEvent extends MatrixMessageContent {
// eslint-disable-next-line camelcase
external_url: string;
"uk.half-shot.matrix-github.comment": {
"uk.half-shot.matrix-hookshot.github.comment": {
id: number;
};
}
Expand Down
4 changes: 3 additions & 1 deletion src/Connections/GenericHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ const TRANSFORMATION_TIMEOUT_MS = 2000;
* Handles rooms connected to a github repo.
*/
export class GenericHookConnection implements IConnection {
static readonly CanonicalEventType = "uk.half-shot.matrix-github.generic.hook";
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.generic.hook";
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.generic.hook";

static readonly EventTypes = [
GenericHookConnection.CanonicalEventType,
GenericHookConnection.LegacyCanonicalEventType,
];

public get hookId() {
Expand Down
8 changes: 5 additions & 3 deletions src/Connections/GithubDiscussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ const md = new markdown();
* Handles rooms connected to a github repo.
*/
export class GitHubDiscussionConnection implements IConnection {
static readonly CanonicalEventType = "uk.half-shot.matrix-github.discussion";
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.discussion";
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.discussion";

static readonly EventTypes = [
GitHubDiscussionConnection.CanonicalEventType, // Legacy event, with an awful name.
GitHubDiscussionConnection.CanonicalEventType,
GitHubDiscussionConnection.LegacyCanonicalEventType,
];

static readonly QueryRoomRegex = /#github_disc_(.+)_(.+)_(\d+):.*/;
Expand Down Expand Up @@ -131,7 +133,7 @@ export class GitHubDiscussionConnection implements IConnection {
formatted_body: md.render(data.comment.body),
msgtype: 'm.text',
external_url: data.comment.html_url,
'uk.half-shot.matrix-github.discussion.comment_id': data.comment.id,
'uk.half-shot.matrix-hookshot.github.discussion.comment_id': data.comment.id,
});
}
}
9 changes: 4 additions & 5 deletions src/Connections/GithubDiscussionSpace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ export interface GitHubDiscussionSpaceConnectionState {
* Handles rooms connected to a github repo.
*/
export class GitHubDiscussionSpace implements IConnection {
static readonly CanonicalEventType = "uk.half-shot.matrix-github.discussion.space";
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.discussion.space";
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.discussion.space";

static readonly EventTypes = [
GitHubDiscussionSpace.CanonicalEventType, // Legacy event, with an awful name.
GitHubDiscussionSpace.CanonicalEventType,
GitHubDiscussionSpace.LegacyCanonicalEventType,
];

static readonly QueryRoomRegex = /#github_disc_(.+)_(.+):.*/;
Expand Down Expand Up @@ -64,9 +66,6 @@ export class GitHubDiscussionSpace implements IConnection {
responseType: 'arraybuffer',
});
log.info(`uploading ${profile.data.avatar_url}`);
// This does exist, but headers is silly and doesn't have content-type.
// tslint:disable-next-line: no-any
console.log(res.headers);
const contentType: string = res.headers["content-type"];
const mxcUrl = await opts.as.botClient.uploadContent(
Buffer.from(res.data as ArrayBuffer),
Expand Down
9 changes: 4 additions & 5 deletions src/Connections/GithubIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ interface IQueryRoomOpts {
* Handles rooms connected to a github repo.
*/
export class GitHubIssueConnection implements IConnection {
static readonly CanonicalEventType = "uk.half-shot.matrix-github.bridge";
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.issue";
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.bridge";

static readonly EventTypes = [
GitHubIssueConnection.CanonicalEventType, // Legacy event, with an awful name.
GitHubIssueConnection.CanonicalEventType,
GitHubIssueConnection.LegacyCanonicalEventType,
];

static readonly QueryRoomRegex = /#github_(.+)_(.+)_(\d+):.*/;
Expand Down Expand Up @@ -84,9 +86,6 @@ export class GitHubIssueConnection implements IConnection {
responseType: 'arraybuffer',
});
log.info(`uploading ${profile.data.avatar_url}`);
// This does exist, but headers is silly and doesn't have content-type.
// tslint:disable-next-line: no-any
console.log(res.headers);
const contentType: string = res.headers["content-type"];
const mxcUrl = await opts.as.botClient.uploadContent(
Buffer.from(res.data as ArrayBuffer),
Expand Down
6 changes: 4 additions & 2 deletions src/Connections/GithubProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ const log = new LogWrapper("GitHubProjectConnection");
* Handles rooms connected to a github repo.
*/
export class GitHubProjectConnection implements IConnection {
static readonly CanonicalEventType = "uk.half-shot.matrix-github.project";
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.project";
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.project";

static readonly EventTypes = [
GitHubProjectConnection.CanonicalEventType, // Legacy event, with an awful name.
GitHubProjectConnection.CanonicalEventType,
GitHubProjectConnection.LegacyCanonicalEventType,
];

static async onOpenProject(project: ProjectsGetResponseData, as: Appservice, inviteUser: string): Promise<GitHubProjectConnection> {
Expand Down
11 changes: 5 additions & 6 deletions src/Connections/GithubRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ function compareEmojiStrings(e0: string, e1: string, e0Index = 0) {
* Handles rooms connected to a github repo.
*/
export class GitHubRepoConnection implements IConnection {
static readonly CanonicalEventType = "uk.half-shot.matrix-github.repository";
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.repository";
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.repository";

static readonly EventTypes = [
GitHubRepoConnection.CanonicalEventType, // Legacy event, with an awful name.
GitHubRepoConnection.CanonicalEventType,
GitHubRepoConnection.LegacyCanonicalEventType,
];

static readonly QueryRoomRegex = /#github_(.+)_(.+):.*/;
Expand Down Expand Up @@ -101,9 +103,6 @@ export class GitHubRepoConnection implements IConnection {
responseType: 'arraybuffer',
});
log.info(`uploading ${profile.data.avatar_url}`);
// This does exist, but headers is silly and doesn't have content-type.
// tslint:disable-next-line: no-any
console.log(res.headers);
const contentType: string = res.headers["content-type"];
const mxcUrl = await opts.as.botClient.uploadContent(
Buffer.from(res.data as ArrayBuffer),
Expand Down Expand Up @@ -481,7 +480,7 @@ ${event.release.body}`;
// eslint-disable-next-line camelcase
const {event_id, key} = (evt.content as MatrixReactionContent)["m.relates_to"];
const ev = await this.as.botClient.getEvent(this.roomId, event_id);
const issueContent = ev.content["uk.half-shot.matrix-github.issue"];
const issueContent = ev.content["uk.half-shot.matrix-hookshot.github.issue"];
if (!issueContent) {
log.debug('Reaction to event did not pertain to a issue');
return; // Not our event.
Expand Down
3 changes: 2 additions & 1 deletion src/Connections/GithubUserSpace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export interface GitHubUserSpaceConnectionState {
* Handles rooms connected to a github repo.
*/
export class GitHubUserSpace implements IConnection {
static readonly CanonicalEventType = "uk.half-shot.matrix-github.user.space";
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.user.space";
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.user.space";

static readonly EventTypes = [
GitHubUserSpace.CanonicalEventType, // Legacy event, with an awful name.
Expand Down
5 changes: 3 additions & 2 deletions src/Connections/GitlabIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ const log = new LogWrapper("GitLabIssueConnection");
* Handles rooms connected to a github repo.
*/
export class GitLabIssueConnection implements IConnection {
static readonly CanonicalEventType = "uk.half-shot.matrix-github.gitlab.issue";
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.gitlab.issue";
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.gitlab.issue";

static readonly EventTypes = [
GitLabIssueConnection.CanonicalEventType,
GitLabIssueConnection.LegacyCanonicalEventType,
];

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

public async onCommentCreated(event: IGitLabWebhookNoteEvent) {
log.info(`${this.toString()} onCommentCreated ${event.object_attributes.noteable_id}`);
console.log(event);
if (event.repository) {
// Delay to stop comments racing sends
await new Promise((resolve) => setTimeout(resolve, 500));
Expand Down
6 changes: 4 additions & 2 deletions src/Connections/GitlabRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ const md = new markdown();
* Handles rooms connected to a github repo.
*/
export class GitLabRepoConnection implements IConnection {
static readonly CanonicalEventType = "uk.half-shot.matrix-github.gitlab.repository";
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.gitlab.repository";
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.gitlab.repository";

static readonly EventTypes = [
GitLabRepoConnection.CanonicalEventType, // Legacy event, with an awful name.
GitLabRepoConnection.CanonicalEventType,
GitLabRepoConnection.LegacyCanonicalEventType,
];

static botCommands: BotCommands;
Expand Down
4 changes: 3 additions & 1 deletion src/Connections/JiraProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ const md = new markdownit();
* Handles rooms connected to a github repo.
*/
export class JiraProjectConnection implements IConnection {
static readonly CanonicalEventType = "uk.half-shot.matrix-github.jira.project";
static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.jira.project";
static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.jira.project";

static readonly EventTypes = [
JiraProjectConnection.CanonicalEventType,
JiraProjectConnection.LegacyCanonicalEventType,
];

static getTopicString(authorName: string, state: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/FormatUtil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub fn get_partial_body_for_jira_issue(ctx: CallContext) -> Result<JsObject, Nap
.create_string_from_std(jira_issue.fields.project._self)?,
)?;

body.set_named_property("uk.half-shot.matrix-github.jira.issue", jira_issue_result)?;
body.set_named_property("uk.half-shot.matrix-github.jira.project", jira_project)?;
body.set_named_property("uk.half-shot.matrix-hookshot.jira.issue", jira_issue_result)?;
body.set_named_property("uk.half-shot.matrix-hookshot.jira.project", jira_project)?;
Ok(body)
}
Loading

0 comments on commit 40a75fa

Please sign in to comment.