From 3a48a7dea50c9de1468972d7345f72a1f0758c69 Mon Sep 17 00:00:00 2001 From: dericksonmark <68699877+dericksonmark@users.noreply.github.com> Date: Thu, 13 Jun 2024 20:20:31 -0400 Subject: [PATCH] Fix version feeds (#293) * Fix version feeds by updating format * Update config to include changes --- config/main.yml | 42 ++++++++++++++++++++---------------- src/BotConfig.ts | 7 +++++- src/tasks/VersionFeedTask.ts | 19 ++++++++-------- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/config/main.yml b/config/main.yml index 19affd46..c9bebd6f 100644 --- a/config/main.yml +++ b/config/main.yml @@ -113,7 +113,7 @@ filterFeeds: # titleSingle: This ticket has just been marked as fixed! # cached: true -versionFeeds: [] +versionFeeds: #java-fixes # - projects: # - MC @@ -139,21 +139,25 @@ versionFeeds: [] # - unreleased #version-feed - # - projects: - # - BDS - # - MC - # - MCD - # - MCL - # - MCPE - # - REALMS - # channel: '741600360619049000' - # publish: true - # interval: 10000 - # scope: 5 - # actions: - # - created - # - archived - # - unarchived - # - released - # - unreleased - # - renamed + - projects: + - name: BDS + id: 11700 + - name: MC + id: 10400 + - name: MCL + id: 11101 + - name: MCPE + id: 10200 + - name: REALMS + id: 11402 + channel: "741600360619049000" + publish: false + interval: 10000 + scope: 5 + actions: + - created + - archived + - unarchived + - released + - unreleased + - renamed diff --git a/src/BotConfig.ts b/src/BotConfig.ts index 6d10d506..ceea3795 100644 --- a/src/BotConfig.ts +++ b/src/BotConfig.ts @@ -95,8 +95,13 @@ export interface FilterFeedConfig { cached?: boolean; } +export interface VersionConfig { + name: string; + id: number; +} + export interface VersionFeedConfig { - projects: string[]; + projects: VersionConfig[]; channel: Snowflake; interval: number; versionFeedEmoji: string | Snowflake; diff --git a/src/tasks/VersionFeedTask.ts b/src/tasks/VersionFeedTask.ts index b63041d3..901d8702 100644 --- a/src/tasks/VersionFeedTask.ts +++ b/src/tasks/VersionFeedTask.ts @@ -1,6 +1,6 @@ import { EmbedBuilder, TextBasedChannel } from 'discord.js'; import log4js from 'log4js'; -import { VersionFeedConfig } from '../BotConfig.js'; +import { VersionConfig, VersionFeedConfig } from '../BotConfig.js'; import { NewsUtil } from '../util/NewsUtil.js'; import MojiraBot from '../MojiraBot.js'; import Task from './Task.js'; @@ -13,7 +13,7 @@ interface JiraVersion { archived: boolean; released: boolean; releaseDate?: string; - project: string; + projectId: number; } function versionConv( version: Version ): JiraVersion | undefined { @@ -22,7 +22,7 @@ function versionConv( version: Version ): JiraVersion | undefined { || version.name === undefined || version.archived === undefined || version.released === undefined - || version.project === undefined + || version.projectId === undefined ) return undefined; return { @@ -31,7 +31,7 @@ function versionConv( version: Version ): JiraVersion | undefined { archived: version.archived, released: version.released, releaseDate: version.releaseDate, - project: version.project, + projectId: version.projectId, }; } @@ -52,7 +52,7 @@ export default class VersionFeedTask extends Task { private static logger = log4js.getLogger( 'VersionFeedTask' ); private channel: TextBasedChannel; - private projects: string[]; + private projects: VersionConfig[]; private versionFeedEmoji: string; private scope: number; private actions: VersionChangeType[]; @@ -75,7 +75,7 @@ export default class VersionFeedTask extends Task { try { for ( const project of this.projects ) { const results = await MojiraBot.jira.projectVersions.getProjectVersions( { - projectIdOrKey: project, + projectIdOrKey: project.name, expand: 'id,name,archived,released', } ); @@ -117,7 +117,7 @@ export default class VersionFeedTask extends Task { const changes: JiraVersionChange[] = []; for ( const project of this.projects ) { - changes.push( ...await this.getVersionChangesForProject( project ) ); + changes.push( ...await this.getVersionChangesForProject( project.name ) ); } return changes.filter( change => this.actions.includes( change.type ) ); @@ -263,10 +263,11 @@ export default class VersionFeedTask extends Task { } ); } - if ( this.projects.length > 1 ) { + const projectKey = this.projects.find( project => project.id == version.projectId )?.name; + if ( projectKey ) { embed.addFields( { name: 'Project', - value: version.project, + value: projectKey, inline: true, } ); }