mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00

* Bridge Gitlab comment replies as Matrix threads * Persistently store Gitlab Discussion-Thread mapping * Remove leftover debug line * Denoise comment descriptions when they happen in Matrix threads * Make comment debouncing time configurable * Add some tests for Gitlab comments * De-only Gitlab comment tests * Linting * Changelog * Map multiple Gitlab discussions to a single Matrix thread We debounce Gitlab comments, so multiple discussions can end up in one thread. This ensures that replies to *any* of these discussions end up in the same thread. * Add tests for the many-to-one reply case * Move SerializedGitlabDiscussionThreads to Types * Update changelog.d/758.feature Co-authored-by: Will Hunt <will@half-shot.uk> * Fix instructions for validating your config using Docker (#794) * Fix instructions for validating your config using Docker Fixes GH-787 * Changelog --------- Co-authored-by: Tadeusz Sośnierz <tadeusz@sosnierz.com> * Add more icons to GitHub messages (#795) * Add more icons to GitHub messages * Add merged icon * Lint * Add changelog * Bump word-wrap from 1.2.3 to 1.2.4 (#799) * Bump word-wrap from 1.2.3 to 1.2.4 Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4. - [Release notes](https://github.com/jonschlinkert/word-wrap/releases) - [Commits](https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.4) --- updated-dependencies: - dependency-name: word-wrap dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Add changelog --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Andrew Ferrazzutti <andrewf@element.io> * Update matrix-appservice-bridge to 9.0.1 (#800) * Bump semver from 5.7.1 to 5.7.2 (#797) Bumps [semver](https://github.com/npm/node-semver) from 5.7.1 to 5.7.2. - [Release notes](https://github.com/npm/node-semver/releases) - [Changelog](https://github.com/npm/node-semver/blob/v5.7.2/CHANGELOG.md) - [Commits](https://github.com/npm/node-semver/compare/v5.7.1...v5.7.2) --- updated-dependencies: - dependency-name: semver dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Will Hunt <will@half-shot.uk> * 4.4.0 * 4.4.1 * Set the default commentDebouncMs for Gitlab in its Config * Rename `approvalState` to something more fitting * Update sample config --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Tadeusz Sośnierz <tadeusz@sosnierz.com> Co-authored-by: Will Hunt <will@half-shot.uk> Co-authored-by: Connor Davis <mail@connordav.is> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Andrew Ferrazzutti <andrewf@element.io>
113 lines
3.5 KiB
TypeScript
113 lines
3.5 KiB
TypeScript
|
|
import { expect } from "chai";
|
|
import { MatrixError } from "matrix-bot-sdk";
|
|
export class MatrixClientMock {
|
|
|
|
static create(){
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
return new this() as any;
|
|
}
|
|
|
|
// map room Id → user Ids
|
|
private joinedMembers: Map<string, string[]> = new Map();
|
|
public readonly roomAccountData: Map<string, string> = new Map();
|
|
|
|
async setDisplayName() {
|
|
return;
|
|
}
|
|
|
|
async getJoinedRoomMembers(roomId: string): Promise<string[]> {
|
|
return this.joinedMembers.get(roomId) || [];
|
|
}
|
|
|
|
async inviteUser(userId: string, roomId: string): Promise<void> {
|
|
const roomMembers = this.joinedMembers.get(roomId) || [];
|
|
|
|
if (roomMembers.includes(userId)) {
|
|
throw new Error("User already in room");
|
|
}
|
|
|
|
roomMembers.push(userId);
|
|
this.joinedMembers.set(roomId, roomMembers);
|
|
}
|
|
|
|
async getRoomAccountData(key: string, roomId: string): Promise<string> {
|
|
const data = this.roomAccountData.get(roomId+key);
|
|
if (data) {
|
|
return data;
|
|
}
|
|
throw new MatrixError({
|
|
errcode: 'M_NOT_FOUND',
|
|
error: 'Test error: No account data',
|
|
}, 404);
|
|
}
|
|
|
|
async setRoomAccountData(key: string, roomId: string, value: string): Promise<void> {
|
|
this.roomAccountData.set(roomId+key, value);
|
|
}
|
|
}
|
|
|
|
export class IntentMock {
|
|
public readonly underlyingClient = new MatrixClientMock();
|
|
public sentEvents: {roomId: string, content: any}[] = [];
|
|
|
|
constructor(readonly userId: string) {}
|
|
|
|
static create(userId: string){
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
return new this(userId) as any;
|
|
}
|
|
|
|
sendText(roomId: string, noticeText: string, msgtype: string) {
|
|
this.sentEvents.push({
|
|
roomId,
|
|
content: {
|
|
msgtype,
|
|
body: noticeText,
|
|
}
|
|
});
|
|
}
|
|
|
|
sendEvent(roomId: string, content: any): Promise<string> {
|
|
this.sentEvents.push({
|
|
roomId,
|
|
content,
|
|
});
|
|
return Promise.resolve(`event_${this.sentEvents.length - 1}`);
|
|
}
|
|
|
|
expectNoEvent() {
|
|
expect(this.sentEvents, 'Expected no events to be sent.').to.be.empty;
|
|
}
|
|
|
|
expectEventBodyContains(matcher: string|RegExp, eventIndex?: number) {
|
|
if (eventIndex !== undefined) {
|
|
expect(this.sentEvents[eventIndex], `Expected event ${eventIndex} to exist`).to.not.be.undefined;
|
|
const body = this.sentEvents[eventIndex].content.body;
|
|
expect(
|
|
body.includes(matcher),
|
|
`Expected event body ${eventIndex} to match '${matcher}'.\nMessage was: '${body}'`
|
|
).to.be.true;
|
|
return;
|
|
}
|
|
expect(!!this.sentEvents.find(ev => ev.content.body.includes(matcher)), `Expected any event body to match '${matcher}'`).to.be.true;
|
|
}
|
|
|
|
expectEventMatches(matcher: (content: any) => boolean, description: string, eventIndex?: number) {
|
|
if (eventIndex !== undefined) {
|
|
expect(this.sentEvents[eventIndex], `Expected event ${eventIndex} to exist`).to.not.be.undefined;
|
|
expect(matcher(this.sentEvents[eventIndex]), description).to.be.true;
|
|
return;
|
|
}
|
|
expect(this.sentEvents.some(ev => matcher(ev)), description).to.be.true;
|
|
}
|
|
|
|
async ensureJoined() {
|
|
return true;
|
|
}
|
|
|
|
async ensureRegistered() {
|
|
return true;
|
|
}
|
|
}
|