Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix version feeds #293

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions config/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ filterFeeds:
# titleSingle: This ticket has just been marked as fixed!
# cached: true

versionFeeds: []
versionFeeds:
#java-fixes
# - projects:
# - MC
Expand All @@ -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
7 changes: 6 additions & 1 deletion src/BotConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 10 additions & 9 deletions src/tasks/VersionFeedTask.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -13,7 +13,7 @@ interface JiraVersion {
archived: boolean;
released: boolean;
releaseDate?: string;
project: string;
projectId: number;
}

function versionConv( version: Version ): JiraVersion | undefined {
Expand All @@ -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 {
Expand All @@ -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,
};
}

Expand All @@ -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[];
Expand All @@ -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',
} );

Expand Down Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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,
} );
}
Expand Down
Loading