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

Change/remove a branch of an open issue #9080

Merged
merged 29 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c7d3b19
Add field with isIssueWriter to front end
Nov 18, 2019
0e106f0
Make branch field editable
Nov 18, 2019
de06054
Switch frontend to form and POST from javascript
Nov 19, 2019
c99c280
Add /issue/id/ref endpoint to routes
Nov 19, 2019
c41a8a9
Use UpdateIssueTitle model to change ref in backend
Nov 19, 2019
b84622d
Removed crossreference check and adding comments on branch change
Nov 19, 2019
668d3c0
Merge branch into master
Nov 20, 2019
92a031f
Use ref returned from POST to update the field
Nov 21, 2019
7d339c1
Prevent calling loadRepo from models/
Nov 21, 2019
20f10af
Branch/tag refreshed without page reload
Nov 21, 2019
9e36b25
Remove filter for empty branch name
Nov 22, 2019
bb1b87f
Add clear option to tag list as well
Nov 22, 2019
8b68d5d
Delete button translation and coloring
Nov 22, 2019
fbf7ad9
Fix for not showing selected branch name in new issue
Nov 24, 2019
619a128
Merge master into branch
Nov 24, 2019
0eac4b6
Merge master into branch
Nov 26, 2019
2bd8e64
Check that branch is not being changed on a PR
Dec 12, 2019
f8a70ce
Merge master into branch
Dec 12, 2019
b913c6e
Change logic
Dec 12, 2019
6c8e3e0
Merge remote-tracking branch 'upstream/master' into change-issue-branch
Jan 26, 2020
d7cd33e
Notification when changing issue ref
Jan 26, 2020
c74afb9
Merge branch 'master' of git://github.com/go-gitea/gitea into change-…
May 17, 2020
c0a77d4
Merge branch 'master' of git://github.com/go-gitea/gitea into change-…
May 17, 2020
52f6763
Fix for renamed permission parameter
May 17, 2020
7d97d58
Fix for failing build
May 17, 2020
f8f8d13
Apply suggestions from code review
Sep 4, 2020
aeb173b
Merge branch 'master' into change-issue-branch
zeripath Sep 4, 2020
0fc8d10
Merge branch 'master' into change-issue-branch
lunny Sep 8, 2020
def127d
Merge branch 'master' into change-issue-branch
techknowlogick Sep 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,26 @@ func (issue *Issue) ChangeTitle(doer *User, oldTitle string) (err error) {
return sess.Commit()
}

// ChangeRef changes the branch of this issue, as the given user.
func (issue *Issue) ChangeRef(doer *User, oldRef string) (err error) {
sess := x.NewSession()
defer sess.Close()

if err = sess.Begin(); err != nil {
return err
}

if err = updateIssueCols(sess, issue, "ref"); err != nil {
return fmt.Errorf("updateIssueCols: %v", err)
}

if err = issue.loadRepo(sess); err != nil {
vedranMv marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("loadRepo: %v", err)
}

return sess.Commit()
}

// AddDeletePRBranchComment adds delete branch comment for pull request issue
func AddDeletePRBranchComment(doer *User, repo *Repository, issueID int64, branchName string) error {
issue, err := getIssueByID(x, issueID)
Expand Down
2 changes: 1 addition & 1 deletion public/js/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/index.js.map

Large diffs are not rendered by default.

30 changes: 29 additions & 1 deletion routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["Participants"] = participants
ctx.Data["NumParticipants"] = len(participants)
ctx.Data["Issue"] = issue
ctx.Data["ReadOnly"] = true
ctx.Data["ReadOnly"] = false
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + ctx.Data["Link"].(string)
ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.User.ID)
ctx.Data["IsIssueWriter"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
Expand Down Expand Up @@ -1055,6 +1055,34 @@ func UpdateIssueTitle(ctx *context.Context) {
})
}

// UpdateIssueRef change issue's ref (branch)
func UpdateIssueRef(ctx *context.Context) {
issue := GetActionIssue(ctx)
if ctx.Written() {
return
}

if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vedranMv This was an oversight from my part. Although the UI will not let the user change the branch on pull requests, please add a check here too so PRs can't be changed by using the API directly.

Also, I think we should also check that the issue is not closed (that check should also be added to the UI).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If user try to change a branch of a PR, we should return an error.

Copy link
Contributor Author

@vedranMv vedranMv Dec 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. Something like 2bd8e64 b913c6e ?
edit:brainfart :D

ctx.Error(403)
return
}

ref := ctx.QueryTrim("ref")
if len(ref) == 0 {
ctx.Error(204)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can the user remove the target branch?

Copy link
Contributor Author

@vedranMv vedranMv Nov 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far it can't, however, that's the same problem as when you try to create an issue - once selected, the branch can't be removed short of refreshing the page. I'll look into it

And thanks for all the feedback, it's pretty useful :)

return
}

if err := issue_service.ChangeIssueRef(issue, ctx.User, ref); err != nil {
ctx.ServerError("ChangeRef", err)
return
}

ctx.JSON(200, map[string]interface{}{
"ref": ref,
})
}

// UpdateIssueContent change issue's content
func UpdateIssueContent(ctx *context.Context) {
issue := GetActionIssue(ctx)
Expand Down
1 change: 1 addition & 0 deletions routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/title", repo.UpdateIssueTitle)
m.Post("/content", repo.UpdateIssueContent)
m.Post("/watch", repo.IssueWatch)
m.Post("/ref", repo.UpdateIssueRef)
m.Group("/dependency", func() {
m.Post("/add", repo.AddDependency)
m.Post("/delete", repo.RemoveDependency)
Expand Down
14 changes: 14 additions & 0 deletions services/issue/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ func ChangeTitle(issue *models.Issue, doer *models.User, title string) (err erro
return nil
}

// ChangeIssueRef changes the branch of this issue, as the given user.
func ChangeIssueRef(issue *models.Issue, doer *models.User, ref string) (err error) {
oldRef := issue.Ref
issue.Ref = ref

if err = issue.ChangeRef(doer, oldRef); err != nil {
return
}
vedranMv marked this conversation as resolved.
Show resolved Hide resolved
// TODO: implement notifications
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a new notification - change branch

//notification.NotifyIssueChangeTitle(doer, issue, oldRef)

return nil
}

// UpdateAssignees is a helper function to add or delete one or multiple issue assignee(s)
// Deleting is done the GitHub way (quote from their api documentation):
// https://developer.github.com/v3/issues/#edit-an-issue
Expand Down
6 changes: 6 additions & 0 deletions templates/repo/issue/branch_selector_field.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{{if and (not .Issue.IsPull) (not .PageIsComparePull)}}
<input id="ref_selector" name="ref" type="hidden" value="{{.Issue.Ref}}">
<input id="editing_mode" name="edit_mode" type="hidden" value="{{.IsIssueWriter}}">
vedranMv marked this conversation as resolved.
Show resolved Hide resolved
<form method="POST" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/ref" id="update_issueref_form">
<input id="api_endpoint" name="api_endpoint" type="hidden" value="{{$.RepoLink}}/issues/{{.Issue.Index}}/title">
{{$.CsrfTokenHtml}}
</form>

<div class="ui {{if .ReadOnly}}disabled{{end}} floating filter select-branch dropdown" data-no-results="{{.i18n.Tr "repo.pulls.no_results"}}">
<div class="ui basic small button">
<span class="text branch-name">{{if .Issue.Ref}}{{.Issue.Ref}}{{else}}{{.i18n.Tr "repo.issues.no_ref"}}{{end}}</span>
Expand Down
13 changes: 13 additions & 0 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,21 @@ function initBranchSelector() {
const $branchMenu = $selectBranch.find('.reference-list-menu');
$branchMenu.find('.item:not(.no-select)').click(function () {
const selectedValue = $(this).data('id');
const editMode = $('#editing_mode').val();
$($(this).data('id-selector')).val(selectedValue);
$selectBranch.find('.ui .branch-name').text(selectedValue);

if (editMode === 'true') {
const form = $('#update_issueref_form');

$.post(form.attr('action'), {
_csrf: csrf,
ref: selectedValue
},
() => {
reload();
});
}
});
$selectBranch.find('.reference.column').click(function () {
$selectBranch.find('.scrolling.reference-list-menu').css('display', 'none');
Expand Down