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

Closed
opened 2025-11-02 04:41:26 -06:00 by GiteaMirror · 3 comments
Owner

Originally created by @juanpablo-santos on GitHub (Nov 30, 2018).

  • Gitea version (or commit ref): 1.6.0
  • Git version: 2.14
  • Operating system:
  • Database (use [x]):
    • PostgreSQL
    • [ X] MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

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

Originally created by @juanpablo-santos on GitHub (Nov 30, 2018). <!-- 1. Please speak English, this is the language all of us can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/NsatcWJ) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): 1.6.0 - Git version: 2.14 - Operating system: - Database (use `[x]`): - [ ] PostgreSQL - [ X] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [ ] Not relevant - Log gist: ## 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
GiteaMirror added the type/enhancement label 2025-11-02 04:41:26 -06:00
Author
Owner

@lafriks commented on GitHub (Nov 30, 2018):

I think there is already PR to fix this

@lafriks commented on GitHub (Nov 30, 2018): I think there is already PR to fix this
Author
Owner

@juanpablo-santos commented on GitHub (Jan 22, 2019):

@lafriks, perhaps #5347?

@juanpablo-santos commented on GitHub (Jan 22, 2019): @lafriks, perhaps #5347?
Author
Owner

@lafriks commented on GitHub (Jan 22, 2019):

yes, closing as fixed

@lafriks commented on GitHub (Jan 22, 2019): yes, closing as fixed
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#2592