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

feat: add a from-GitHub Jira label to Jira issues. #279 #281

Merged
merged 2 commits into from
Nov 27, 2023
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
6 changes: 6 additions & 0 deletions changelog.d/20231120_114120_nedbat_from_github_label_279.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. A new scriv changelog fragment.

- Now issues created in Jira will have a label of "from-GitHub" on them. Closes
`issue 279`_.

.. _issue 279: https://github.com/openedx/openedx-webhooks/issues/279
2 changes: 2 additions & 0 deletions docs/details.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,5 @@ bot will create a Jira issue in the Jira server with the "xyz" nickname.

Each Jira server can specify a mapping of repos to other Jira details such as
the Jira project for the issue, and the issue type to create.

Jira issues created this way will have a "from-GitHub" Jira label applied.
4 changes: 1 addition & 3 deletions openedx_webhooks/tasks/pr_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ class PrDesiredInfo:
# don't need to force a new status, but can leave the existing status.
jira_status: Optional[str] = None

jira_labels: Set[str] = field(default_factory=set)

# The bot-controlled labels we want to on the pull request.
# See labels.py:CATEGORY_LABELS
github_labels: Set[str] = field(default_factory=set)
Expand Down Expand Up @@ -411,7 +409,7 @@ def _make_jira_issue(self, jira_nick) -> None:
issuetype=issuetype,
summary=self.desired.jira_title,
description=self.desired.jira_description,
labels=list(self.desired.jira_labels),
labels=["from-GitHub"],
)

jira_id = JiraId(jira_nick, issue_data["key"])
Expand Down
10 changes: 10 additions & 0 deletions tests/fake_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dataclasses
import itertools
import re
from dataclasses import dataclass, field
from typing import Dict, Optional, Set

Expand All @@ -26,6 +27,15 @@ class Issue:
summary: Optional[str] = None
labels: Set[str] = field(default_factory=set)

def __post_init__(self) -> None:
# Jira labels can't have spaces in them. Check that they are only
# letters, numbers, dashes.
for label in self.labels:
if re.search(r"[^a-zA-Z0-9-]", label):
raise ValueError(f"Label {label!r} has invalid characters")
if len(label) < 3:
raise ValueError(f"Label {label!r} is too short")

def as_json(self) -> Dict:
return {
"key": self.key,
Expand Down
9 changes: 8 additions & 1 deletion tests/test_fake_jira.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests of FakeJira."""

import pytest
import requests


Expand All @@ -10,7 +11,7 @@ class TestIssues:
Tests of the correct behavior of issuees.
"""
def test_get_issue(self, fake_jira):
fake_jira.make_issue(key="HELLO-123", summary="This is a bad bug!")
fake_jira.make_issue(key="HELLO-123", summary="This is a bad bug!", labels=["bad-bug"])
resp = requests.get("https://test.atlassian.net/rest/api/2/issue/HELLO-123")
assert resp.status_code == 200
issue = resp.json()
Expand Down Expand Up @@ -74,3 +75,9 @@ class TestBadRequests:
def test_no_such_put(self, fake_jira):
resp = requests.put("https://test.atlassian.net/rest/api/2/issue/XYZ-999")
assert resp.status_code == 404

def test_bad_label(self, fake_jira):
with pytest.raises(ValueError, match="Label 'a bug' has invalid characters"):
fake_jira.make_issue(key="HELLO-123", summary="a bug!", labels=["a bug"])
with pytest.raises(ValueError, match="Label 'a' is too short"):
fake_jira.make_issue(key="HELLO-123", summary="a bug!", labels="a bug")
1 change: 1 addition & 0 deletions tests/test_pull_request_opened.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ def test_jira_labelling(fake_github, fake_jira, fake_jira2):
Line2
"""
)
assert jira_issue.labels == {"from-GitHub"}

# Processing the pull request again won't make another issue.
result = pull_request_changed(pr.as_json())
Expand Down
Loading