From 3b40bc6bce8d252cca736f99e855b50545280874 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 13 Mar 2025 22:28:56 +0100 Subject: [PATCH] Allow the bot to work with Jira Cloud --- .gitignore | 1 + config/local.template.yml | 3 ++- config/template.yml | 3 ++- src/BotConfig.ts | 12 ++++++++---- src/commands/SearchCommand.ts | 2 +- src/tasks/VersionFeedTask.ts | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 10e72480..13bba956 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ node_modules .vscode/* .history **/.DS_Store +.idea/ **/*.log settings.json diff --git a/config/local.template.yml b/config/local.template.yml index 58c057c5..9fce4a1a 100644 --- a/config/local.template.yml +++ b/config/local.template.yml @@ -1,6 +1,6 @@ # 1. Copy this file # 2. Rename the copy to `local.yml` -# 3. Change the bot token, and your Jira personal access token if desired, and save the file +# 3. Change the bot token, and your Jira email+personal access token if desired, and save the file # # You can add more configs if you want to. # @@ -11,4 +11,5 @@ # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! token: +jireUser: jiraPat: diff --git a/config/template.yml b/config/template.yml index 4a3d4042..35995bc8 100644 --- a/config/template.yml +++ b/config/template.yml @@ -11,8 +11,9 @@ logDirectory: # Your bot token used to log in to Discord with the bot. token: -# Your Jira personal access token. +# Your Jira E-Mail and personal access token. # Optional; if not assigned a value, the bot will not attempt to log into Jira. +jiraUser: jiraPat: # A list of user IDs for owner only commands. diff --git a/src/BotConfig.ts b/src/BotConfig.ts index ceea3795..14e1f74c 100644 --- a/src/BotConfig.ts +++ b/src/BotConfig.ts @@ -116,6 +116,7 @@ export default class BotConfig { private static token: string; private static jiraPat?: string; + private static jiraUser?: string; public static owners: Snowflake[]; @@ -149,6 +150,7 @@ export default class BotConfig { this.logDirectory = getOrDefault( 'logDirectory', false ); this.token = config.get( 'token' ); + this.jiraUser = getOrDefault( 'jiraUser', undefined ); this.jiraPat = getOrDefault( 'jiraPat', undefined ); this.owners = getOrDefault( 'owners', [] ); @@ -194,10 +196,12 @@ export default class BotConfig { public static jiraLogin(): void { // TODO: integrate newErrorHandling from Jira.js MojiraBot.jira = new JiraClient( { - host: 'https://bugs.mojang.com', - telemetry: false, - authentication: this.jiraPat === undefined ? undefined : { - personalAccessToken: this.jiraPat, + host: 'https://mojira.atlassian.net', + authentication: this.jiraPat === undefined || this.jiraUser === undefined ? undefined : { + basic: { + email: this.jiraUser, + apiToken: this.jiraPat, + }, }, } ); } diff --git a/src/commands/SearchCommand.ts b/src/commands/SearchCommand.ts index 4f6350b2..2bf8890c 100644 --- a/src/commands/SearchCommand.ts +++ b/src/commands/SearchCommand.ts @@ -21,7 +21,7 @@ export default class SearchCommand extends SlashCommand { try { const embed = new EmbedBuilder(); - const searchFilter = `text ~ "${ plainArgs }" AND project in (${ BotConfig.projects.join( ', ' ) })`; + const searchFilter = `(description ~ "${ plainArgs }" OR summary ~ "${ plainArgs }") AND project in (${ BotConfig.projects.join( ', ' ) })`; const searchResults = await MojiraBot.jira.issueSearch.searchForIssuesUsingJql( { jql: searchFilter, maxResults: BotConfig.maxSearchResults, diff --git a/src/tasks/VersionFeedTask.ts b/src/tasks/VersionFeedTask.ts index 7a6d065d..6202f2b1 100644 --- a/src/tasks/VersionFeedTask.ts +++ b/src/tasks/VersionFeedTask.ts @@ -13,7 +13,7 @@ interface JiraVersion { archived: boolean; released: boolean; releaseDate?: string; - projectId: number; + projectId: number | string; } function versionConv( version: Version ): JiraVersion | undefined {