-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Change/remove a branch of an open issue #9080
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
Changes from 7 commits
c7d3b19
0e106f0
de06054
c99c280
c41a8a9
b84622d
668d3c0
92a031f
7d339c1
20f10af
9e36b25
bb1b87f
8b68d5d
fbf7ad9
619a128
0eac4b6
2bd8e64
f8a70ce
b913c6e
6c8e3e0
d7cd33e
c74afb9
c0a77d4
52f6763
7d97d58
f8f8d13
aeb173b
0fc8d10
def127d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the delay. Something like |
||
ctx.Error(403) | ||
return | ||
} | ||
|
||
ref := ctx.QueryTrim("ref") | ||
if len(ref) == 0 { | ||
ctx.Error(204) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can the user remove the target branch? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Uh oh!
There was an error while loading. Please reload this page.