Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying branch in issues #3620

Closed
thehowl opened this issue Mar 3, 2018 · 10 comments · Fixed by #9080
Closed

Modifying branch in issues #3620

thehowl opened this issue Mar 3, 2018 · 10 comments · Fixed by #9080
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/enhancement An improvement of existing functionality

Comments

@thehowl
Copy link
Contributor

thehowl commented 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.

@lunny lunny added the type/enhancement An improvement of existing functionality label Mar 3, 2018
@jalcine
Copy link

jalcine commented 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

@baradhili
Copy link

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?

@loup-brun
Copy link

+1 on @baradhili

@stale
Copy link

stale bot commented 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 stale bot added the issue/stale label May 20, 2019
@lunny lunny added the issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented label May 20, 2019
@stale stale bot removed the issue/stale label May 20, 2019
@rhuesken
Copy link

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

@hauke68
Copy link

hauke68 commented 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.

@loup-brun
Copy link

+1

2 similar comments
@jwegner
Copy link

jwegner commented Sep 21, 2019

+1

@nightsparc
Copy link

+1

@vedranMv
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants