Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
* upstream/main:
  Fix a bug returning 404 when display a single tag with no release (go-gitea#29466)
  Add a check for when the command is canceled by the program on Window… (go-gitea#29538)
  Fix incorrect redirection when creating a PR fails (go-gitea#29537)
  Fix incorrect subpath in links (go-gitea#29535)
  Fix issue link does not support quotes (go-gitea#29484) (go-gitea#29487)
  • Loading branch information
zjjhot committed Mar 2, 2024
2 parents ad3fe09 + cc27b50 commit 768e1ba
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 38 deletions.
12 changes: 12 additions & 0 deletions modules/git/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"io"
"os"
"os/exec"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -344,6 +345,17 @@ func (c *Command) Run(opts *RunOpts) error {
log.Debug("slow git.Command.Run: %s (%s)", c, elapsed)
}

// We need to check if the context is canceled by the program on Windows.
// This is because Windows does not have signal checking when terminating the process.
// It always returns exit code 1, unlike Linux, which has many exit codes for signals.
if runtime.GOOS == "windows" &&
err != nil &&
err.Error() == "" &&
cmd.ProcessState.ExitCode() == 1 &&
ctx.Err() == context.Canceled {
return ctx.Err()
}

if err != nil && ctx.Err() != context.DeadlineExceeded {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions modules/references/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ var (
// mentionPattern matches all mentions in the form of "@user" or "@org/team"
mentionPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@[0-9a-zA-Z-_]+|@[0-9a-zA-Z-_]+\/?[0-9a-zA-Z-_]+|@[0-9a-zA-Z-_][0-9a-zA-Z-_.]+\/?[0-9a-zA-Z-_.]+[0-9a-zA-Z-_])(?:\s|[:,;.?!]\s|[:,;.?!]?$|\)|\])`)
// issueNumericPattern matches string that references to a numeric issue, e.g. #1287
issueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[|\')([#!][0-9]+)(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`)
issueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[|\'|\")([#!][0-9]+)(?:\s|$|\)|\]|\'|\"|[:;,.?!]\s|[:;,.?!]$)`)
// issueAlphanumericPattern matches string that references to an alphanumeric issue, e.g. ABC-1234
issueAlphanumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([A-Z]{1,10}-[1-9][0-9]*)(?:\s|$|\)|\]|:|\.(\s|$))`)
issueAlphanumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[|\"|\')([A-Z]{1,10}-[1-9][0-9]*)(?:\s|$|\)|\]|:|\.(\s|$)|\"|\')`)
// crossReferenceIssueNumericPattern matches string that references a numeric issue in a different repository
// e.g. org/repo#12345
crossReferenceIssueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+[#!][0-9]+)(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`)
Expand Down
4 changes: 4 additions & 0 deletions modules/references/references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ func TestRegExp_issueNumericPattern(t *testing.T) {
" #12",
"#12:",
"ref: #12: msg",
"\"#1234\"",
"'#1234'",
}
falseTestCases := []string{
"# 1234",
Expand Down Expand Up @@ -459,6 +461,8 @@ func TestRegExp_issueAlphanumericPattern(t *testing.T) {
"(ABC-123)",
"[ABC-123]",
"ABC-123:",
"\"ABC-123\"",
"'ABC-123'",
}
falseTestCases := []string{
"RC-08",
Expand Down
4 changes: 2 additions & 2 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1792,9 +1792,9 @@ pulls.unrelated_histories = Merge Failed: The merge head and base do not share a
pulls.merge_out_of_date = Merge Failed: Whilst generating the merge, the base was updated. Hint: Try again.
pulls.head_out_of_date = Merge Failed: Whilst generating the merge, the head was updated. Hint: Try again.
pulls.has_merged = Failed: The pull request has been merged, you cannot merge again or change the target branch.
pulls.push_rejected = Merge Failed: The push was rejected. Review the Git Hooks for this repository.
pulls.push_rejected = Push Failed: The push was rejected. Review the Git Hooks for this repository.
pulls.push_rejected_summary = Full Rejection Message
pulls.push_rejected_no_message = Merge Failed: The push was rejected but there was no remote message.<br>Review the Git Hooks for this repository
pulls.push_rejected_no_message = Push Failed: The push was rejected but there was no remote message. Review the Git Hooks for this repository
pulls.open_unmerged_pull_exists = `You cannot perform a reopen operation because there is a pending pull request (#%d) with identical properties.`
pulls.status_checking = Some checks are pending
pulls.status_checks_success = All checks were successful
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ func CompareAndPullRequestPost(ctx *context.Context) {
return
}
ctx.Flash.Error(flashError)
ctx.JSONRedirect(pullIssue.Link()) // FIXME: it's unfriendly, and will make the content lost
ctx.JSONRedirect(ctx.Link + "?" + ctx.Req.URL.RawQuery) // FIXME: it's unfriendly, and will make the content lost
return
}
ctx.ServerError("NewPullRequest", err)
Expand Down
9 changes: 9 additions & 0 deletions routers/web/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ func Releases(ctx *context.Context) {
ctx.ServerError("getReleaseInfos", err)
return
}
for _, rel := range releases {
if rel.Release.IsTag && rel.Release.Title == "" {
rel.Release.Title = rel.Release.TagName
}
}

ctx.Data["Releases"] = releases

Expand Down Expand Up @@ -283,6 +288,7 @@ func SingleRelease(ctx *context.Context) {
TagNames: []string{ctx.Params("*")},
// only show draft releases for users who can write, read-only users shouldn't see draft releases.
IncludeDrafts: writeAccess,
IncludeTags: true,
})
if err != nil {
ctx.ServerError("getReleaseInfos", err)
Expand All @@ -294,6 +300,9 @@ func SingleRelease(ctx *context.Context) {
}

release := releases[0].Release
if release.IsTag && release.Title == "" {
release.Title = release.TagName
}

ctx.Data["PageIsSingleTag"] = release.IsTag
if release.IsTag {
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/diff/comments.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<div class="comment-header-right actions gt-df gt-ac">
{{if .Invalidated}}
{{$referenceUrl := printf "%s#%s" $.root.Issue.Link .HashTag}}
<a href="{{AppSubUrl}}{{$referenceUrl}}" class="ui label basic small" data-tooltip-content="{{ctx.Locale.Tr "repo.issues.review.outdated_description"}}">
<a href="{{$referenceUrl}}" class="ui label basic small" data-tooltip-content="{{ctx.Locale.Tr "repo.issues.review.outdated_description"}}">
{{ctx.Locale.Tr "repo.issues.review.outdated"}}
</a>
{{end}}
Expand Down
8 changes: 0 additions & 8 deletions templates/repo/diff/compare.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
{{ctx.Locale.Tr "action.compare_commits_general"}}
{{end}}
</h2>
{{if .Flash.WarningMsg}}
{{/*
There's already an importing of alert.tmpl in new_form.tmpl,
but only the negative message will be displayed within forms for some reasons, see semantic.css:10659.
To avoid repeated negative messages, the importing here if for .Flash.WarningMsg only.
*/}}
{{template "base/alert" .}}
{{end}}
{{$BaseCompareName := $.BaseName -}}
{{- $HeadCompareName := $.HeadRepo.OwnerName -}}
{{- if and (eq $.BaseName $.HeadRepo.OwnerName) (ne $.Repository.Name $.HeadRepo.Name) -}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/diff/conversation.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
We only handle the case $resolved=true and $invalid=true in this template because if the comment is not resolved it has the outdated label in the comments area (not the header above).
The case $resolved=false and $invalid=true is handled in repo/diff/comments.tmpl
-->
<a href="{{AppSubUrl}}{{$referenceUrl}}" class="ui label basic small gt-ml-3" data-tooltip-content="{{ctx.Locale.Tr "repo.issues.review.outdated_description"}}">
<a href="{{$referenceUrl}}" class="ui label basic small gt-ml-3" data-tooltip-content="{{ctx.Locale.Tr "repo.issues.review.outdated_description"}}">
{{ctx.Locale.Tr "repo.issues.review.outdated"}}
</a>
{{end}}
Expand Down
8 changes: 0 additions & 8 deletions templates/repo/issue/new.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
<div role="main" aria-label="{{.Title}}" class="page-content repository new issue">
{{template "repo/header" .}}
<div class="ui container">
{{if .Flash.WarningMsg}}
{{/*
There's already an importing of alert.tmpl in new_form.tmpl,
but only the negative message will be displayed within forms for some reasons, see semantic.css:10659.
To avoid repeated negative messages, the importing here if for .Flash.WarningMsg only.
*/}}
{{template "base/alert" .}}
{{end}}
{{template "repo/issue/new_form" .}}
</div>
</div>
Expand Down
8 changes: 3 additions & 5 deletions templates/repo/issue/new_form.tmpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{{if .Flash}}
{{template "base/alert" .}}
{{end}}
<form class="issue-content ui comment form form-fetch-action" id="new-issue" action="{{.Link}}" method="post">
{{.CsrfTokenHtml}}
{{if .Flash}}
<div class="sixteen wide column">
{{template "base/alert" .}}
</div>
{{end}}
<div class="issue-content-left">
<div class="ui comments">
<div class="comment">
Expand Down
6 changes: 3 additions & 3 deletions templates/repo/release/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
<div class="ui twelve wide column detail">
<div class="gt-df gt-ac gt-sb gt-fw gt-mb-3">
<h4 class="release-list-title gt-word-break">
<a href="{{$.RepoLink}}/releases/tag/{{$release.TagName | PathEscapeSegments}}">{{$release.Title}}</a>
{{if $.PageIsSingleTag}}{{$release.Title}}{{else}}<a href="{{$.RepoLink}}/releases/tag/{{$release.TagName | PathEscapeSegments}}">{{$release.Title}}</a>{{end}}
{{template "repo/commit_statuses" dict "Status" $info.CommitStatus "Statuses" $info.CommitStatuses "AdditionalClasses" "gt-df"}}
{{if $release.IsDraft}}
<span class="ui yellow label">{{ctx.Locale.Tr "repo.release.draft"}}</span>
{{else if $release.IsPrerelease}}
<span class="ui orange label">{{ctx.Locale.Tr "repo.release.prerelease"}}</span>
{{else}}
{{else if (not $release.IsTag)}}
<span class="ui green label">{{ctx.Locale.Tr "repo.release.stable"}}</span>
{{end}}
</h4>
<div>
{{if $.CanCreateRelease}}
{{if and $.CanCreateRelease (not $.PageIsSingleTag)}}
<a class="muted" data-tooltip-content="{{ctx.Locale.Tr "repo.release.edit"}}" href="{{$.RepoLink}}/releases/edit/{{$release.TagName | PathEscapeSegments}}" rel="nofollow">
{{svg "octicon-pencil"}}
</a>
Expand Down
6 changes: 3 additions & 3 deletions templates/repo/release_tag_header.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<div class="gt-df">
<div class="gt-f1 gt-df gt-ac">
<h2 class="ui compact small menu header small-menu-items">
<a class="{{if .PageIsReleaseList}}active {{end}}item" href="{{.RepoLink}}/releases">{{ctx.Locale.PrettyNumber .NumReleases}} {{ctx.Locale.TrN .NumReleases "repo.release" "repo.releases"}}</a>
<a class="{{if and .PageIsReleaseList (not .PageIsSingleTag)}}active {{end}}item" href="{{.RepoLink}}/releases">{{ctx.Locale.PrettyNumber .NumReleases}} {{ctx.Locale.TrN .NumReleases "repo.release" "repo.releases"}}</a>
{{if $canReadCode}}
<a class="{{if .PageIsTagList}}active {{end}}item" href="{{.RepoLink}}/tags">{{ctx.Locale.PrettyNumber .NumTags}} {{ctx.Locale.TrN .NumTags "repo.tag" "repo.tags"}}</a>
<a class="{{if or .PageIsTagList .PageIsSingleTag}}active {{end}}item" href="{{.RepoLink}}/tags">{{ctx.Locale.PrettyNumber .NumTags}} {{ctx.Locale.TrN .NumTags "repo.tag" "repo.tags"}}</a>
{{end}}
</h2>
</div>
Expand All @@ -17,7 +17,7 @@
</a>
{{end}}
{{if and (not .PageIsTagList) .CanCreateRelease}}
<a class="ui small primary button" href="{{$.RepoLink}}/releases/new">
<a class="ui small primary button" href="{{$.RepoLink}}/releases/new{{if .PageIsSingleTag}}?tag={{.TagName}}{{end}}">
{{ctx.Locale.Tr "repo.release.new_release"}}
</a>
{{end}}
Expand Down
1 change: 1 addition & 0 deletions tests/integration/links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestLinksNoLogin(t *testing.T) {
"/user2/repo1/",
"/user2/repo1/projects",
"/user2/repo1/projects/1",
"/user2/repo1/releases/tag/delete-tag", // It's the only one existing record on release.yml which has is_tag: true
"/assets/img/404.png",
"/assets/img/500.png",
"/.well-known/security.txt",
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function initNotificationCount() {
type: 'close',
});
worker.port.close();
window.location.href = appSubUrl;
window.location.href = `${appSubUrl}/`;
} else if (event.data.type === 'close') {
worker.port.postMessage({
type: 'close',
Expand Down
9 changes: 7 additions & 2 deletions web_src/js/features/repo-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ function initTagNameEditor() {
const newTagHelperText = el.getAttribute('data-tag-helper-new');
const existingTagHelperText = el.getAttribute('data-tag-helper-existing');

document.getElementById('tag-name').addEventListener('keyup', (e) => {
const value = e.target.value;
const tagNameInput = document.getElementById('tag-name');
const hideTargetInput = function(tagNameInput) {
const value = tagNameInput.value;
const tagHelper = document.getElementById('tag-helper');
if (existingTags.includes(value)) {
// If the tag already exists, hide the target branch selector.
Expand All @@ -41,6 +42,10 @@ function initTagNameEditor() {
showElem('#tag-target-selector');
tagHelper.textContent = value ? newTagHelperText : defaultTagHelperText;
}
};
hideTargetInput(tagNameInput); // update on page load because the input may have a value
tagNameInput.addEventListener('input', (e) => {
hideTargetInput(e.target);
});
}

Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/stopwatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function initStopwatch() {
type: 'close',
});
worker.port.close();
window.location.href = appSubUrl;
window.location.href = `${appSubUrl}/`;
} else if (event.data.type === 'close') {
worker.port.postMessage({
type: 'close',
Expand Down

0 comments on commit 768e1ba

Please sign in to comment.