feat: fhs mattermost (#626)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
Daniel Dietzler
2026-09-10 15:29:24 +02:00
committed by GitHub
co-authored by renovate[bot]
parent d884b56c8a
commit daf053b537
4 changed files with 73 additions and 23 deletions
+5
View File
@@ -22,10 +22,12 @@ export enum DiscordField {
export enum GithubRepo {
Immich = 'immich',
StaticPages = 'static-pages',
FHSCore = 'fhs-core',
}
export enum GithubOrg {
ImmichApp = 'immich-app',
FUTO = 'futo-org',
}
export const IMMICH_REPOSITORY_BASE_OPTIONS = { owner: 'immich-app', repo: 'immich' };
@@ -121,10 +123,13 @@ const mattermostChannels = {
GithubIssuesAndDiscussions: 'zpn38kj84pyg3bmbj7d66kdnge',
GithubPullRequests: 'i1fbjrqj67n1ibx4f6isuioguc',
GithubReleases: '97d9ihrnb3rwbcoob6erhdfrcr',
FHSGithubPullRequests: 'b3dajyaywffymb8updr8sb64ay',
FHSGithubReleases: 'ggnayby577f45reuin1j143xsc',
};
const mattermostTeams = {
Immich: 'ejumard7n7budjfeayghjrr3or',
FHS: 'ewmb789rq3ya98sjkeqoon4y5y',
};
export const Constants = {
+20 -5
View File
@@ -70,6 +70,16 @@ const GITHUB_THREAD_REGEX = new RegExp(`(${GITHUB_PAGE_REGEX.source})|(${GITHUB_
const GITHUB_FILE_REGEX =
/https:\/\/github.com\/(?<org>[\w\-.,]+)\/(?<repo>[\w\-.,]+)\/blob\/(?<ref>[\w\-.,]+)\/(?<path>[\w\-.,/%\d]+)(#L(?<lineFrom>\d+)(-L(?<lineTo>\d+))?)?/g;
const defaultGithubOrg = {
[Constants.Mattermost.Teams.Immich]: GithubOrg.ImmichApp,
[Constants.Mattermost.Teams.FHS]: GithubOrg.FUTO,
};
const defaultGithubRepo = {
[Constants.Mattermost.Teams.Immich]: GithubRepo.Immich,
[Constants.Mattermost.Teams.FHS]: GithubRepo.FHSCore,
};
@Injectable()
export class ChatService {
private logger = new Logger(ChatService.name);
@@ -107,7 +117,10 @@ export class ChatService {
return;
}
const messageParts = await this.handleGithubReferences({ content: post.message }, true);
const messageParts = await this.handleGithubReferences(
{ content: post.message, teamId: msg.broadcast.team_id },
true,
);
if (messageParts.length !== 0) {
await this.mattermost.updatePost({
@@ -315,11 +328,11 @@ ${messageParts.join('\n')}`,
}
async handleGithubReferences(
{ content, channelParentId }: { content: string; channelParentId?: string | null },
{ content, channelParentId, teamId }: { content: string; channelParentId?: string | null; teamId?: string },
isPrivileged: boolean,
) {
const codeSnippets = await this.handleGithubFileReferences(content, isPrivileged);
const links = await this.handleGithubThreadReferences({ content, channelParentId }, isPrivileged);
const links = await this.handleGithubThreadReferences({ content, channelParentId, teamId }, isPrivileged);
return [...codeSnippets, ...links].filter((e) => e !== undefined);
}
@@ -328,9 +341,11 @@ ${messageParts.join('\n')}`,
{
content,
channelParentId,
teamId,
}: {
content: string;
channelParentId?: string | null;
teamId?: string;
},
isPrivileged: boolean,
) {
@@ -360,8 +375,8 @@ ${messageParts.join('\n')}`,
links.push({
id,
org: org || orgPage || latestPr?.organization || GithubOrg.ImmichApp,
repo: repo || repoPage || latestPr?.repository || GithubRepo.Immich,
org: org || orgPage || latestPr?.organization || (teamId ? defaultGithubOrg[teamId] : GithubOrg.ImmichApp),
repo: repo || repoPage || latestPr?.repository || (teamId ? defaultGithubRepo[teamId] : GithubRepo.Immich),
type: latestPr ? 'pull' : (category as LinkType),
discordThreadId:
channelParentId === undefined
+6
View File
@@ -15,5 +15,11 @@ export class MattermostService {
await this.mattermost.joinChannel(channel.id);
}
}
for await (const channel of this.mattermost.streamChannels(Constants.Mattermost.Teams.FHS)) {
if (channel.create_at > DateTime.now().minus({ days: 1 }).toMillis()) {
await this.mattermost.joinChannel(channel.id);
}
}
}
}
+42 -18
View File
@@ -80,9 +80,10 @@ export class WebhookService {
case 'pull_request_review_thread': {
const { payload } = event;
await this.upsertPullRequest(payload);
await this.handlePullRequestNotification(payload);
if (!payload.repository.private) {
await Promise.all([this.handlePullRequestTeamUpdate(payload), this.handlePullRequestNotification(payload)]);
await this.handlePullRequestTeamUpdate(payload);
}
break;
}
@@ -120,9 +121,7 @@ export class WebhookService {
case 'release': {
const { payload } = event;
if (!payload.repository.private) {
await Promise.all([this.handleReleaseNotification(payload), this.handleCreateReleaseNotes(payload)]);
}
await Promise.all([this.handleReleaseNotification(payload), this.handleCreateReleaseNotes(payload)]);
break;
}
}
@@ -751,13 +750,24 @@ export class WebhookService {
embed.setColor(color);
mattermostBlock.accent_color = color ? asHexColor(Colors[color]) : undefined;
await this.discord.sendMessage({ channelId: DiscordChannel.PullRequests, message: { embeds: [embed] } });
await this.mattermost.send({
channelId: Constants.Mattermost.Channels.GithubPullRequests,
message: '',
silent: true,
props: { mm_blocks: [mattermostBlock] },
});
if (repository.owner.login === GithubOrg.ImmichApp) {
if (!repository.private) {
await this.discord.sendMessage({ channelId: DiscordChannel.PullRequests, message: { embeds: [embed] } });
}
await this.mattermost.send({
channelId: Constants.Mattermost.Channels.GithubPullRequests,
message: '',
silent: true,
props: { mm_blocks: [mattermostBlock] },
});
} else if (repository.owner.login === GithubOrg.FUTO && repository.name === GithubRepo.FHSCore) {
await this.mattermost.send({
channelId: Constants.Mattermost.Channels.FHSGithubPullRequests,
message: '',
silent: true,
props: { mm_blocks: [mattermostBlock] },
});
}
}
}
@@ -838,14 +848,28 @@ export class WebhookService {
user: sender,
description: isMainRepo(repository.full_name) ? _.sample(ReleaseMessages) : undefined,
};
if (repository.owner.login === GithubOrg.FUTO && repository.name === GithubRepo.FHSCore) {
await this.mattermost.send({
channelId: Constants.Mattermost.Channels.FHSGithubReleases,
message: '',
props: { mm_blocks: [this.getReleaseMattermostBlock(embedProps)] },
});
return;
}
const messages = [
this.discord.sendMessage({
channelId: DiscordChannel.Releases,
message: {
embeds: [this.getReleaseEmbed(embedProps)],
},
crosspost: true,
}),
...(repository.private
? []
: [
this.discord.sendMessage({
channelId: DiscordChannel.Releases,
message: {
embeds: [this.getReleaseEmbed(embedProps)],
},
crosspost: true,
}),
]),
this.mattermost.send({
channelId: Constants.Mattermost.Channels.GithubReleases,
message: '',