Skip to content

Commit 33db8f7

Browse files
committed
Add support for editing labels #346
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 4a6dae5 commit 33db8f7

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

workflow/integrations/github.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def sync(self, request):
4646
title=self.make_issue_title(request),
4747
body=self.make_issue_body(request),
4848
state="closed" if request.is_closed else "open",
49+
labels=labels,
4950
)
5051
else:
5152
issue = self.create_issue(
@@ -78,7 +79,7 @@ def create_issue(self, repo_id, title, body="", labels=None):
7879
response.raise_for_status()
7980
return response.json()
8081

81-
def update_issue(self, repo_id, issue_id, title=None, body=None, state=None):
82+
def update_issue(self, repo_id, issue_id, title=None, body=None, state=None, labels=None):
8283
"""Update an existing GitHub issue."""
8384
url = f"{self.api_url}/repos/{repo_id}/issues/{issue_id}"
8485
data = {}
@@ -88,6 +89,8 @@ def update_issue(self, repo_id, issue_id, title=None, body=None, state=None):
8889
data["body"] = body
8990
if state:
9091
data["state"] = state
92+
if labels:
93+
data["labels"] = labels
9194

9295
response = self.session.patch(
9396
url,

workflow/integrations/gitlab.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def sync(self, request):
4949
title=self.make_issue_title(request),
5050
body=self.make_issue_body(request),
5151
state_event="close" if request.is_closed else "reopen",
52+
labels=labels,
5253
)
5354
else:
5455
issue = self.create_issue(
@@ -83,7 +84,7 @@ def create_issue(self, repo_id, title, body="", labels=None):
8384
response.raise_for_status()
8485
return response.json()
8586

86-
def update_issue(self, repo_id, issue_id, title=None, body=None, state_event=None):
87+
def update_issue(self, repo_id, issue_id, title=None, body=None, state_event=None, labels=None):
8788
"""Update an existing GitLab issue."""
8889
project_path = quote(repo_id, safe="")
8990
url = f"{self.api_url}/projects/{project_path}/issues/{issue_id}"
@@ -94,6 +95,9 @@ def update_issue(self, repo_id, issue_id, title=None, body=None, state_event=Non
9495
data["description"] = body
9596
if state_event:
9697
data["state_event"] = state_event
98+
if labels:
99+
# GitLab expects a comma-separated string for labels
100+
data["labels"] = ",".join(labels)
97101

98102
response = self.session.put(
99103
url,

0 commit comments

Comments
 (0)