Skip to content

Commit

Permalink
Allow for setting default labels on Jira issues created from Quality-…
Browse files Browse the repository at this point in the history
…time. The labels can be configured in the issue tracker tab under the report header. Closes #4468.
  • Loading branch information
fniessink committed Sep 8, 2022
1 parent ce52430 commit 2ebbb62
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 4 deletions.
2 changes: 2 additions & 0 deletions components/external_server/src/model/issue_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class IssueTracker:
url: URL
project_key: str
issue_type: str
issue_labels: list[str] = None
username: str = ""
password: str = ""
private_token: str = ""
Expand All @@ -50,6 +51,7 @@ def create_issue(self, summary: str, description: str = "") -> tuple[str, str]:
issuetype=dict(name=self.issue_type),
summary=summary,
description=description,
labels=self.issue_labels or [],
)
)
try:
Expand Down
3 changes: 2 additions & 1 deletion components/external_server/src/model/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def issue_tracker(self) -> IssueTracker:
url = parameters.get("url", "")
project_key = parameters.get("project_key", "")
issue_type = parameters.get("issue_type", "")
issue_labels = parameters.get("issue_labels", [])
username = parameters.get("username", "")
password = parameters.get("password", "")
private_token = parameters.get("private_token", "")
return IssueTracker(url, project_key, issue_type, username, password, private_token)
return IssueTracker(url, project_key, issue_type, issue_labels, username, password, private_token)
11 changes: 9 additions & 2 deletions components/external_server/tests/model/test_issue_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def test_url(self):

def test_username_and_password(self):
"""Test the issue tracker credentials."""
issue_tracker = IssueTracker(self.ISSUE_TRACKER_URL, self.PROJECT_KEY, self.ISSUE_TYPE, "username", "password")
issue_tracker = IssueTracker(
self.ISSUE_TRACKER_URL, self.PROJECT_KEY, self.ISSUE_TYPE, [], "username", "password"
)
self.assertEqual("username", issue_tracker.username)
self.assertEqual("password", issue_tracker.password)

Expand All @@ -34,6 +36,11 @@ def test_private_token(self):
issue_tracker = IssueTracker(self.ISSUE_TRACKER_URL, self.PROJECT_KEY, self.ISSUE_TYPE, private_token="token")
self.assertEqual("token", issue_tracker.private_token)

def test_issue_labels(self):
"""Test the issue tracker issue labels."""
issue_tracker = IssueTracker(self.ISSUE_TRACKER_URL, self.PROJECT_KEY, self.ISSUE_TYPE, ["Label"])
self.assertEqual(["Label"], issue_tracker.issue_labels)

@patch("requests.get")
def test_get_suggestions(self, requests_get):
"""Test that issue suggestions are returned."""
Expand Down Expand Up @@ -70,7 +77,7 @@ def test_create_issue_with_invalid_url(self):
)
logging.disable(logging.NOTSET)

def test_create_issue_withoutd_url(self):
def test_create_issue_without_url(self):
"""Test that without a URL an error message is returned."""
issue_tracker = IssueTracker("", "", "")
logging.disable(logging.CRITICAL)
Expand Down
1 change: 1 addition & 0 deletions components/external_server/tests/routes/test_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ def test_add_metric_issue(self, requests_post, request):
"fields": {
"project": {"key": "KEY"},
"issuetype": {"name": "BUG"},
"labels": [],
"summary": "Quality-time metric 'name'",
"description": "Metric '[name|https://quality_time/metric42]' of subject "
"'Subject' in Quality-time report '' needs attention.\n\n"
Expand Down
13 changes: 13 additions & 0 deletions components/frontend/src/report/IssueTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { StringInput } from '../fields/StringInput';
import { HyperLink } from '../widgets/HyperLink';
import { set_report_issue_tracker_attribute } from '../api/report';
import { EDIT_REPORT_PERMISSION } from '../context/Permissions';
import { MultipleChoiceInput } from '../fields/MultipleChoiceInput';
import { SingleChoiceInput } from '../fields/SingleChoiceInput';
import { PasswordInput } from '../fields/PasswordInput';
import { Logo } from '../source/Logo';
Expand Down Expand Up @@ -123,6 +124,18 @@ export function IssueTracker({ report, reload }) {
/>
</Grid.Column>
</Grid.Row>
<Grid.Row columns={1}>
<Grid.Column>
<MultipleChoiceInput
allowAdditions
id="tracker-issue-labels"
requiredPermissions={[EDIT_REPORT_PERMISSION]}
label="Labels for new issues"
set_value={(value) => set_report_issue_tracker_attribute(report_uuid, "issue_labels", value, reload)}
value={report.issue_tracker?.parameters?.issue_labels}
/>
</Grid.Column>
</Grid.Row>
</Grid>
)
}
8 changes: 8 additions & 0 deletions components/frontend/src/report/IssueTracker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,11 @@ it('sets the issue tracker issue type', async () => {
await userEvent.type(screen.getByText(/Issue type/), 'bug{Enter}');
expect(fetch_server_api.fetch_server_api).toHaveBeenLastCalledWith("post", "report/report_uuid/issue_tracker/issue_type", { issue_type: "bug" });
});

it('sets the issue tracker issue labels', async () => {
await act(async () => {
render_issue_tracker();
});
await userEvent.type(screen.getByText(/No results found/), 'Label{Enter}');
expect(fetch_server_api.fetch_server_api).toHaveBeenLastCalledWith("post", "report/report_uuid/issue_tracker/issue_labels", { issue_labels: ["Label"] });
});
1 change: 1 addition & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ If your currently installed *Quality-time* version is not v4.3.0, please read th
- When creating issues, include the rationale for the metric in the created issue so that people encountering the issue in the issue tracker have a better understanding of why the issue needs addressing. Closes [#4232](https://github.com/ICTU/quality-time/issues/4232).
- When measuring violations with SonarQube as source, add the selected issue types (bug, vulnerability, and/or code smell) and severities (info, minor, major, critical, and/or blocker) to the landing URL so that the user sees only the relevant violations when navigating to SonarQube. Closes [#4449](https://github.com/ICTU/quality-time/issues/4449).
- Make Jira issue identifiers uppercase when querying Jira for the status of issues, so that users don't have to enter uppercase Jira identifiers in *Quality-time*. Closes [#4450](https://github.com/ICTU/quality-time/issues/4450).
- Allow for setting default labels on Jira issues created from *Quality-time*. The labels can be configured in the issue tracker tab under the report header. Closes [#4468](https://github.com/ICTU/quality-time/issues/4468).

## v4.3.0 - 2022-08-24

Expand Down
2 changes: 1 addition & 1 deletion docs/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ $ curl --cookie cookie.txt --request POST --header "Content-Type: application/js

## Issue tracker

To track work being done on metrics, for example to resolve technical debt, it's possible to add (identifiers of) issues to metrics. *Quality-time* uses these issue identifiers to check the status of the issue with an issue tracker. For this to work, an issue tracker needs to be added to the report. Expand the report header and configure the issue tracker in the issue tracker tab. Currently, only Jira can be used as issue tracker. Please consider submitting a pull request if you need support for other issue trackers such as Azure DevOps or GitLab.
To track work being done on metrics, for example to resolve technical debt, it's possible to add (identifiers of) issues to metrics. *Quality-time* uses these issue identifiers to check the status of the issue with an issue tracker. For this to work, an issue tracker needs to be added to the report. Expand the report header and configure the issue tracker in the issue tracker tab. Currently, only Jira can be used as issue tracker. Please consider submitting a pull request if you need support for other issue trackers such as Azure DevOps Server or GitLab.

Multiple issues can be linked to one metric. At most one issue tracker can be configured per report.

Expand Down

0 comments on commit 2ebbb62

Please sign in to comment.