Gitea: Modifying branch in issues

Created on 3 Mar 2018  路  10Comments  路  Source: go-gitea/gitea

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.

kinenhancement revieweconfirmed

Most helpful comment

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?

All 10 comments

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

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?

+1 on @baradhili

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.

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

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.

+1

+1

+1

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,"--")

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonasfranz picture jonasfranz  路  3Comments

Fastidious picture Fastidious  路  3Comments

thehowl picture thehowl  路  3Comments

mirhec picture mirhec  路  3Comments

flozz picture flozz  路  3Comments