Skip to content

Commit

Permalink
Fix lastRun string replacement in jql queries
Browse files Browse the repository at this point in the history
Previously this only replaced the first occurrence of "lastRun".
Changed to a global regex, and also made it more obvious that it's a variable.
  • Loading branch information
violine1101 authored Aug 21, 2024
1 parent 2316123 commit 1990942
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 53 deletions.
2 changes: 1 addition & 1 deletion config/beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ roleGroups:
emoji: '🇴'

filterFeeds:
- jql: updated > lastRun
- jql: updated > {{lastRun}}
jqlRemoved: ''
channel: '665904688616701953'
publish: true
Expand Down
94 changes: 47 additions & 47 deletions config/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ roleGroups:

filterFeeds:
#java-triage
- jql: project = MC AND status changed by bugnet after lastRun
- jql: project = MC AND status changed BY bugnet AFTER {{lastRun}}
channel: '1275197626719141888' # new channel #java-triage
publish: true
interval: 300000
Expand All @@ -99,7 +99,7 @@ filterFeeds:
cached: false

#java-fixes
- jql: project = MC AND resolved > lastRun AND resolution = Fixed AND fixVersion in unreleasedVersions()
- jql: project = MC AND resolved > {{lastRun}} AND resolution = Fixed AND fixVersion in unreleasedVersions()
channel: '666349583227682819'
publish: true
interval: 30000
Expand All @@ -109,7 +109,7 @@ filterFeeds:
cached: false

# bedrock-fixes
- jql: project IN (MCPE, BDS) AND (resolution changed to Fixed after lastRun OR fixVersion changed after lastRun) AND fixVersion != EMPTY
- jql: project IN (MCPE, BDS) AND (resolution CHANGED TO Fixed AFTER {{lastRun}} OR fixVersion CHANGED AFTER {{lastRun}}) AND fixVersion != EMPTY
channel: '974302728719314974'
publish: true
interval: 30000
Expand All @@ -120,51 +120,51 @@ filterFeeds:

versionFeeds:
#java-fixes
- projects:
- name: MC
id: 10400
channel: '666349583227682819'
publish: true
interval: 10000
scope: 5
versionFeedEmoji: '🎉'
actions:
- released
- unreleased
- projects:
- name: MC
id: 10400
channel: '666349583227682819'
publish: true
interval: 10000
scope: 5
versionFeedEmoji: '🎉'
actions:
- released
- unreleased

#bedrock-fixes
- projects:
- name: MCPE
id: 10200
channel: '974302728719314974'
publish: true
interval: 10000
scope: 5
versionFeedEmoji: '🎉'
actions:
- released
- unreleased
- projects:
- name: MCPE
id: 10200
channel: '974302728719314974'
publish: true
interval: 10000
scope: 5
versionFeedEmoji: '🎉'
actions:
- released
- unreleased

#version-feed
- 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
- 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
2 changes: 1 addition & 1 deletion config/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ filterFeeds:
publish: <boolean>

# Whether the bot should cache tickets in the filter feed,
# If false, the property lastRun should be included in the jql, but when true, the filter feed will be less efficient.
# If false, the variable {{lastRun}} should be included in the jql, but when true, the filter feed will be less efficient.
# Optional; true by default.
cached: <boolean>

Expand Down
7 changes: 4 additions & 3 deletions src/tasks/CachedFilterFeedTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import MojiraBot from '../MojiraBot.js';

export default class CachedFilterFeedTask extends Task {
private static logger = log4js.getLogger( 'CachedFilterFeedTask' );
private static lastRunRegex = /\{\{lastRun\}\}/g;

private channel: TextBasedChannel;
private jql: string;
Expand Down Expand Up @@ -37,7 +38,7 @@ export default class CachedFilterFeedTask extends Task {
this.lastRun = new Date().valueOf();

const searchResults = await MojiraBot.jira.issueSearch.searchForIssuesUsingJql( {
jql: this.jql.replace( 'lastRun', this.lastRun.toString() ),
jql: this.jql.replace( CachedFilterFeedTask.lastRunRegex, this.lastRun.toString() ),
fields: ['key'],
} );

Expand All @@ -53,7 +54,7 @@ export default class CachedFilterFeedTask extends Task {

try {
const searchResults = await MojiraBot.jira.issueSearch.searchForIssuesUsingJql( {
jql: this.jql.replace( 'lastRun', this.lastRun.toString() ),
jql: this.jql.replace( CachedFilterFeedTask.lastRunRegex, this.lastRun.toString() ),
fields: ['key'],
} );

Expand All @@ -72,7 +73,7 @@ export default class CachedFilterFeedTask extends Task {
try {
const ticketKeys = Array.from( this.knownTickets );
const previousTicketResults = await MojiraBot.jira.issueSearch.searchForIssuesUsingJql( {
jql: `${ this.jqlRemoved.replace( 'lastRun', this.lastRun.toString() ) } AND key in (${ ticketKeys.join( ',' ) })`,
jql: `${ this.jqlRemoved.replace( CachedFilterFeedTask.lastRunRegex, this.lastRun.toString() ) } AND key in (${ ticketKeys.join( ',' ) })`,
fields: ['key'],
} );

Expand Down
3 changes: 2 additions & 1 deletion src/tasks/FilterFeedTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { LoggerUtil } from '../util/LoggerUtil.js';

export default class FilterFeedTask extends Task {
private static logger = log4js.getLogger( 'FilterFeedTask' );
private static lastRunRegex = /\{\{lastRun\}\}/g;

private channel: TextBasedChannel;
private jql: string;
Expand Down Expand Up @@ -39,7 +40,7 @@ export default class FilterFeedTask extends Task {

try {
const searchResults = await MojiraBot.jira.issueSearch.searchForIssuesUsingJql( {
jql: this.jql.replace( 'lastRun', this.lastRun.toString() ),
jql: this.jql.replace( FilterFeedTask.lastRunRegex, this.lastRun.toString() ),
fields: ['key'],
} );

Expand Down

0 comments on commit 1990942

Please sign in to comment.