go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
45.07k stars 5.49k forks source link

Unable to add label to a PR from Rest API #5435

Closed juanpablo-santos closed 5 years ago

juanpablo-santos commented 5 years ago

Description

As title says, it seems not possible to add a label to a PR through existing REST API. A /repos/{owner}/{repo}/pulls/{index} PATCH request using { "labels": [ 182 ] } as body (with that label being present for that repo) returns a 201 but the label is not added.

when using this approach xorm.log yields (selects omitted):

2018/11/30 13:21:31 [I] [SQL] UPDATE `webhook` SET `last_status` = ?, `updated_unix` = ? WHERE `id`=? []interface {}{1, 1543584091, 208}
2018/11/30 13:21:32 [I] [SQL] UPDATE `issue_user` SET is_read=? WHERE uid=? AND issue_id=? []interface {}{true, 5, 14879}
2018/11/30 13:22:30 [I] [SQL] UPDATE `issue` SET `repo_id` = ?, `index` = ?, `poster_id` = ?, `name` = ?, `content` = ?, `milestone_id` = ?, `priority` = ?, `is_closed` = ?, `is_pull` = ?, `num_comments` = ?, `ref` = ?, `deadline_unix` = ?, `closed_unix` = ?, `updated_unix` = ? WHERE `id`=? []interface {}{276, 215, 5, "test auto label", "testtesttesttesttesttest", 0, 0, false, true, 0, "", 0, 0, 1543584150, 14879}
2018/11/30 13:23:12 [I] [SQL] UPDATE `issue_user` SET is_read=? WHERE uid=? AND issue_id=? []interface {}{true, 5, 14879}

whereas, when manually adding the label to the PR, xorm.log shows (selects also omitted):

2018/11/30 13:19:03 [I] [SQL] UPDATE `webhook` SET `last_status` = ?, `updated_unix` = ? WHERE `id`=? []interface {}{1, 1543583943, 208}
2018/11/30 13:19:04 [I] [SQL] UPDATE `issue_user` SET is_read=? WHERE uid=? AND issue_id=? []interface {}{true, 5, 14879}
2018/11/30 13:19:26 [I] [SQL] BEGIN TRANSACTION
2018/11/30 13:19:26 [I] [SQL] INSERT INTO `issue_label` (`issue_id`,`label_id`) VALUES (?, ?) []interface {}{14879, 182}
2018/11/30 13:19:26 [I] [SQL] INSERT INTO `comment` (`type`,`poster_id`,`issue_id`,`label_id`,`old_milestone_id`,`milestone_id`,`assignee_id`,`removed_assignee`,`old_title`,`new_title`,`dependent_issue_id`,`commit_id`,`line`,`tree_path`,`content`,`patch`,`created_unix`,`updated_unix`,`commit_sha`,`review_id`,`invalidated`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) []interface {}{7, 5, 14879, 182, 0, 0, 0, false, "", "", 0, 0, 0, "", "1", "", 1543583966, 1543583966, "", 0, false}
2018/11/30 13:19:26 [I] [SQL] UPDATE `issue` SET `updated_unix` = ? WHERE `id`=? []interface {}{1543583966, 14879}
2018/11/30 13:19:26 [I] [SQL] UPDATE `label` SET `repo_id` = ?, `name` = ?, `description` = ?, `color` = ?, `num_issues` = ?, `num_closed_issues` = ? WHERE `id`=? []interface {}{276, "lgtm/need 1", "needs another review in order to be merged", "#fbca04", 1, 0, 182}
2018/11/30 13:19:26 [I] [SQL] COMMIT

Current workaround is to use instead a PUT request to /repos/{owner}/{repo}/issues/{index}/labels using the same index and set the label on the PR through the issues endpoint

lafriks commented 5 years ago

I think there is already PR to fix this

juanpablo-santos commented 5 years ago

@lafriks, perhaps #5347?

lafriks commented 5 years ago

yes, closing as fixed