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

Quote project key in JQL query and provide failure printing. #254

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

MattLud
Copy link

@MattLud MattLud commented Feb 20, 2025

Context

Due to how JIRA project naming works, it will allow project keys with JQL reserved keywords. When used without quotes, the JQL will fail and throw an error message that you must quote them. Since quoting the project key has no downside, doing so will ensure compatibility regardless of project key.

Issue ticket number and link

Checklist before requesting a review

  • I have performed a self-review of my own code
  • I have verified that the code builds perfectly fine on my local system
  • I have verified that my code follows the style already available in the repository
  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)

For some reason Jira allows you to create projects that are also JQL keywords. 

Even when using the project ID #, the API will end up using the key. 

The result is that the response contains an error: 

```
"Error in the JQL Query: 'DO' is a reserved JQL word. You must surround it in quotation marks to use it in a query. (line 1, character 13)"
```

Quoting the project key on the JQL should have no impacts and ensure that the proper query is done.
Prints the error returned by the JQL query if it fails.
@MattLud MattLud requested a review from a team as a code owner February 20, 2025 19:21
Copy link

changeset-bot bot commented Feb 20, 2025

🦋 Changeset detected

Latest commit: eb13a1d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@axis-backstage/plugin-jira-dashboard-backend Minor
backend Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@anicke
Copy link
Contributor

anicke commented Feb 24, 2025

Thank you, please create a changeset. :shipit:

@MattLud
Copy link
Author

MattLud commented Mar 3, 2025

Ok - I believe it's there though I'm new to typescript projects/yarn packaging.

@@ -58,7 +58,11 @@ export const getIssuesByFilter = async (
const issues: Issue[] = [];
for (const project of projects) {
const { projectKey, instance } = project;
const jql = jqlQueryBuilder({ project: [projectKey], components, query });
const jql = jqlQueryBuilder({
project: ['"' + projectKey + '"'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a template string makes most sense here?

      project: `"${projectKey}"`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be better to do it inside the "jqlQueryBuilder" function? We already escape the "components" argument in the same way. There is other uses of the "jqlQueryBuilder" as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! Modified that jql builder function to support it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were using single qoutes for escaping whitespaces in the "component" query. Can't we use the same for projects?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok - should updateIssuesByComponent also be updated to use the JQLBuilder as well?

const projectKeys = projects.map(project => project.projectKey).join(',');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Project keys using reserved JQL keywords silently fail to retrieve issues.
2 participants