Modifying branch in issues #1589

Closed
opened 2025-11-02 04:05:51 -06:00 by GiteaMirror · 11 comments
Owner

Originally created by @thehowl on GitHub (Mar 3, 2018).

From the forums: https://discourse.gitea.io/t/associating-existing-issue-with-a-branch/218/2?u=howl

#780 added the ability to link an issue to a certain branch. However, the branch can't be modified or removed afterwards, so that should be added.

Originally created by @thehowl on GitHub (Mar 3, 2018). From the forums: https://discourse.gitea.io/t/associating-existing-issue-with-a-branch/218/2?u=howl #780 added the ability to link an issue to a certain branch. However, the branch can't be modified or removed afterwards, so that should be added.
GiteaMirror added the issue/confirmedtype/enhancement labels 2025-11-02 04:05:51 -06:00
Author
Owner

@jalcine commented on GitHub (Jan 2, 2019):

Definitely something I'd love to see. What's required for this? From the issue; there's a mention of needing editing support for branches

@jalcine commented on GitHub (Jan 2, 2019): Definitely something I'd love to see. What's required for this? From the issue; there's a mention of needing [editing support for branches](https://github.com/go-gitea/gitea/pull/780)
Author
Owner

@baradhili commented on GitHub (Mar 1, 2019):

I kinda feel its all backwards.. after all my workflow normally has the issue being created first. Then work starting sometime later.. so selecting the branch at the time of creation makes not much sense... I'm assuming originally this was to associate the issue with a release branch, not a bugfix/feature branch?

@baradhili commented on GitHub (Mar 1, 2019): I kinda feel its all backwards.. after all my workflow normally has the issue being created first. Then work starting sometime later.. so selecting the branch at the time of creation makes not much sense... I'm assuming originally this was to associate the issue with a release branch, not a bugfix/feature branch?
Author
Owner

@loup-brun commented on GitHub (Mar 21, 2019):

+1 on @baradhili

@loup-brun commented on GitHub (Mar 21, 2019): +1 on @baradhili
Author
Owner

@stale[bot] commented on GitHub (May 20, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (May 20, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
Author
Owner

@rhuesken commented on GitHub (Jun 20, 2019):

This is also something I would like to see in a future version

@rhuesken commented on GitHub (Jun 20, 2019): This is also something I would like to see in a future version
Author
Owner

@hauke68 commented on GitHub (Sep 20, 2019):

Because I use Gitea a lot, I would also like to see that feature in the future. Maybe naming the branch depending on the issue's headline.

@hauke68 commented on GitHub (Sep 20, 2019): Because I use Gitea a lot, I would also like to see that feature in the future. Maybe naming the branch depending on the issue's headline.
Author
Owner

@loup-brun commented on GitHub (Sep 21, 2019):

+1

@loup-brun commented on GitHub (Sep 21, 2019): +1
Author
Owner

@jwegner commented on GitHub (Sep 21, 2019):

+1

@jwegner commented on GitHub (Sep 21, 2019): +1
Author
Owner

@nightsparc commented on GitHub (Oct 29, 2019):

+1

@nightsparc commented on GitHub (Oct 29, 2019): +1
Author
Owner

@vedranMv commented on GitHub (Nov 15, 2019):

One dirty way around this issue could be to setup triggers in db. I have been testing the following for the past few days in MySQL db with satisfactory results:

CREATE TRIGGER update_issue_ref AFTER INSERT 
ON action FOR EACH ROW
BEGIN 
    SET @op_type=(SELECT op_type FROM action ORDER BY id DESC LIMIT 1);
    SET @last_ref=(SELECT ref_name FROM action ORDER BY id DESC LIMIT 1); 
    SET @last_repoId=(SELECT repo_id FROM action ORDER BY id DESC LIMIT 1); 
    IF @op_type = 5 THEN
        UPDATE issue SET issue.ref=@last_ref WHERE (issue.ref='') AND (@last_ref LIKE CONCAT("%#",issue.index) AND (@last_repoId=repo_id));
    END IF; 
END;

Every time a new branch has been created, this will update branch name for an issue matching these criteria:

  • issue has to have no branch assigned (issue.ref=''),
  • branch has to be created (op_type=5), to avoid updates on branch deletion which seems to be op_type=17
  • branch name has to end with a hashtag and issue number (@last_ref LIKE CONCAT("%#",issue.index) e.g. branch-to-fix-#5 to be assigned to issue #5 and it has to be created in the same repository (@last_repoId=repo_id))

Obvious limitations (and possible expansions) are:

  • Branch can be changed only once, when the branch satisfying the conditions above has been created. However, if (issue.ref='') is removed, branch will be updated every time a branch ending with #<issueID> has been created.
  • Deleting a branch gets the system in a state where link points to non existing state (although branch is still present under 'Deleted branches'). To handle this, one could expand the trigger above to clear ref when a branch has been deleted
CREATE TRIGGER update_issue_ref AFTER INSERT 
ON action FOR EACH ROW
BEGIN 
    SET @op_type=(SELECT op_type FROM action ORDER BY id DESC LIMIT 1);
    SET @last_ref=(SELECT ref_name FROM action ORDER BY id DESC LIMIT 1); 
    SET @last_repoId=(SELECT repo_id FROM action ORDER BY id DESC LIMIT 1); 
    IF @op_type = 5 THEN
        UPDATE issue SET issue.ref=@last_ref WHERE (issue.ref='') AND (@last_ref LIKE CONCAT("%#",issue.index) AND (@last_repoId=repo_id));
    ELSEIF @op_type = 17 THEN
        UPDATE issue SET issue.ref='' WHERE (@last_ref LIKE CONCAT("%#",issue.index) AND (@last_repoId=repo_id));
    END IF; 
END;

However, beware of https://github.com/go-gitea/gitea/pull/9003: if you use this method, having # in a branch name will break the link. Perhaps use a different convention that does not require escaping characters - maybe start with issue id followed by '--' (@last_ref LIKE CONCAT(issue.index,"--")

@vedranMv commented on GitHub (Nov 15, 2019): One dirty way around this issue could be to setup triggers in db. I have been testing the following for the past few days in MySQL db with satisfactory results: ``` CREATE TRIGGER update_issue_ref AFTER INSERT ON action FOR EACH ROW BEGIN SET @op_type=(SELECT op_type FROM action ORDER BY id DESC LIMIT 1); SET @last_ref=(SELECT ref_name FROM action ORDER BY id DESC LIMIT 1); SET @last_repoId=(SELECT repo_id FROM action ORDER BY id DESC LIMIT 1); IF @op_type = 5 THEN UPDATE issue SET issue.ref=@last_ref WHERE (issue.ref='') AND (@last_ref LIKE CONCAT("%#",issue.index) AND (@last_repoId=repo_id)); END IF; END; ``` Every time a new branch has been created, this will update branch name for an issue matching these criteria: * issue has to have no branch assigned (issue.ref=''), * branch has to be created (op_type=5), to avoid updates on branch deletion which seems to be op_type=17 * branch name has to end with a hashtag and issue number ``(@last_ref LIKE CONCAT("%#",issue.index)`` e.g. ``branch-to-fix-#5`` to be assigned to issue ``#5`` and it has to be created in the same repository ``(@last_repoId=repo_id))`` Obvious limitations (and possible expansions) are: * Branch can be changed only once, when the branch satisfying the conditions above has been created. However, if ``(issue.ref='')`` is removed, branch will be updated every time a branch ending with ``#<issueID>`` has been created. * Deleting a branch gets the system in a state where link points to non existing state (although branch is still present under 'Deleted branches'). To handle this, one could expand the trigger above to clear ref when a branch has been deleted ``` CREATE TRIGGER update_issue_ref AFTER INSERT ON action FOR EACH ROW BEGIN SET @op_type=(SELECT op_type FROM action ORDER BY id DESC LIMIT 1); SET @last_ref=(SELECT ref_name FROM action ORDER BY id DESC LIMIT 1); SET @last_repoId=(SELECT repo_id FROM action ORDER BY id DESC LIMIT 1); IF @op_type = 5 THEN UPDATE issue SET issue.ref=@last_ref WHERE (issue.ref='') AND (@last_ref LIKE CONCAT("%#",issue.index) AND (@last_repoId=repo_id)); ELSEIF @op_type = 17 THEN UPDATE issue SET issue.ref='' WHERE (@last_ref LIKE CONCAT("%#",issue.index) AND (@last_repoId=repo_id)); END IF; END; ``` However, beware of https://github.com/go-gitea/gitea/pull/9003: if you use this method, having # in a branch name will break the link. Perhaps use a different convention that does not require escaping characters - maybe start with issue id followed by '--' ``(@last_ref LIKE CONCAT(issue.index,"--")``
Author
Owner

@wxiaoguang commented on GitHub (Dec 10, 2024):

After 8 years, this "branch selector" does nothing more than saving the branch/tag name into database and display it.

Are there real users who uses this feature? If no, could it be removed in new versions?

For anyone who still needs it, please provide feedbacks to Prepare to remove the branch/tag selector in the issue sidebar #32744

If no feedback, then this "branch/tag selector" will be removed in 1.23

@wxiaoguang commented on GitHub (Dec 10, 2024): After 8 years, this "branch selector" does nothing more than saving the branch/tag name into database and display it. Are there real users who uses this feature? If no, could it be removed in new versions? For anyone who still needs it, please provide feedbacks to Prepare to remove the branch/tag selector in the issue sidebar #32744 If no feedback, then this "branch/tag selector" will be removed in 1.23
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#1589