Skip to content

Commit 841efd7

Browse files
committed
Merge remote-tracking branch 'upstream/release/v1.17' into codeberg-1.17
2 parents 9117d8c + 07d1406 commit 841efd7

File tree

13 files changed

+100
-55
lines changed

13 files changed

+100
-55
lines changed

models/issues/issue_list.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010

1111
"code.gitea.io/gitea/models/db"
12+
project_model "code.gitea.io/gitea/models/project"
1213
repo_model "code.gitea.io/gitea/models/repo"
1314
user_model "code.gitea.io/gitea/models/user"
1415
"code.gitea.io/gitea/modules/container"
@@ -222,6 +223,46 @@ func (issues IssueList) loadMilestones(ctx context.Context) error {
222223
return nil
223224
}
224225

226+
func (issues IssueList) getProjectIDs() []int64 {
227+
ids := make(map[int64]struct{}, len(issues))
228+
for _, issue := range issues {
229+
projectID := issue.ProjectID()
230+
if _, ok := ids[projectID]; !ok {
231+
ids[projectID] = struct{}{}
232+
}
233+
}
234+
return container.KeysInt64(ids)
235+
}
236+
237+
func (issues IssueList) loadProjects(ctx context.Context) error {
238+
projectIDs := issues.getProjectIDs()
239+
if len(projectIDs) == 0 {
240+
return nil
241+
}
242+
243+
projectMaps := make(map[int64]*project_model.Project, len(projectIDs))
244+
left := len(projectIDs)
245+
for left > 0 {
246+
limit := db.DefaultMaxInSize
247+
if left < limit {
248+
limit = left
249+
}
250+
err := db.GetEngine(ctx).
251+
In("id", projectIDs[:limit]).
252+
Find(&projectMaps)
253+
if err != nil {
254+
return err
255+
}
256+
left -= limit
257+
projectIDs = projectIDs[limit:]
258+
}
259+
260+
for _, issue := range issues {
261+
issue.Project = projectMaps[issue.ProjectID()]
262+
}
263+
return nil
264+
}
265+
225266
func (issues IssueList) loadAssignees(ctx context.Context) error {
226267
if len(issues) == 0 {
227268
return nil
@@ -495,6 +536,10 @@ func (issues IssueList) loadAttributes(ctx context.Context) error {
495536
return fmt.Errorf("issue.loadAttributes: loadMilestones: %v", err)
496537
}
497538

539+
if err := issues.loadProjects(ctx); err != nil {
540+
return fmt.Errorf("issue.loadAttributes: loadProjects: %v", err)
541+
}
542+
498543
if err := issues.loadAssignees(ctx); err != nil {
499544
return fmt.Errorf("issue.loadAttributes: loadAssignees: %v", err)
500545
}

modules/ssh/ssh.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,21 @@ func sessionHandler(session ssh.Session) {
7575
ctx, cancel := context.WithCancel(session.Context())
7676
defer cancel()
7777

78+
gitProtocol := ""
79+
for _, env := range session.Environ() {
80+
if strings.HasPrefix(env, "GIT_PROTOCOL=") {
81+
// The value would be version=2, so using normal split doesn't work here.
82+
gitProtocol = strings.SplitN(env, "=", 2)[1]
83+
break
84+
}
85+
}
86+
7887
cmd := exec.CommandContext(ctx, setting.AppPath, args...)
7988
cmd.Env = append(
8089
os.Environ(),
8190
"SSH_ORIGINAL_COMMAND="+command,
8291
"SKIP_MINWINSVC=1",
92+
"GIT_PROTOCOL="+gitProtocol,
8393
)
8494

8595
stdout, err := cmd.StdoutPipe()

templates/repo/clone_buttons.tmpl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,7 @@
99
SSH
1010
</button>
1111
{{end}}
12-
<!-- the value will be updated by initRepoCloneLink, the code below is used to avoid UI flicking -->
13-
<input id="repo-clone-url" value="" size="1" readonly>
14-
<script>
15-
(() => {
16-
const proto = localStorage.getItem('repo-clone-protocol') || 'https';
17-
const btn = document.getElementById(`repo-clone-${proto}`);
18-
// it's ok if we don't find the btn here, initRepoCloneLink will take care of it
19-
document.getElementById('repo-clone-url').value = btn ? btn.getAttribute('data-link') : '';
20-
})();
21-
</script>
12+
<input id="repo-clone-url" class="js-clone-url" value="{{$.CloneButtonOriginLink.HTTPS}}" size="1" readonly>
2213
<button class="ui basic icon button tooltip" id="clipboard-btn" data-content="{{.i18n.Tr "copy_url"}}" data-clipboard-target="#repo-clone-url" aria-label="{{.i18n.Tr "copy_url"}}">
2314
{{svg "octicon-paste"}}
2415
</button>

templates/repo/clone_script.tmpl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script>
2+
// synchronously set clone button states and urls here to avoid flickering
3+
// on page load. initRepoCloneLink calls this when proto changes.
4+
// TODO: This localStorage setting should be moved to backend user config
5+
// so it's available during rendering, then this inline script can be removed.
6+
(window.updateCloneStates = function() {
7+
const httpsBtn = document.getElementById('repo-clone-https');
8+
const sshBtn = document.getElementById('repo-clone-ssh');
9+
const value = localStorage.getItem('repo-clone-protocol') || 'https';
10+
const isSSH = value === 'ssh' && sshBtn || value !== 'ssh' && !httpsBtn;
11+
12+
if (httpsBtn) httpsBtn.classList[!isSSH ? 'add' : 'remove']('primary');
13+
if (sshBtn) sshBtn.classList[isSSH ? 'add' : 'remove']('primary');
14+
15+
const btn = isSSH ? sshBtn : httpsBtn;
16+
if (!btn) return;
17+
18+
const link = btn.getAttribute('data-link');
19+
for (const el of document.getElementsByClassName('js-clone-url')) {
20+
el[el.nodeName === 'INPUT' ? 'value' : 'textContent'] = link;
21+
}
22+
})();
23+
</script>

templates/repo/empty.tmpl

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ git init
3737
{{if ne .Repository.DefaultBranch "master"}}git checkout -b {{.Repository.DefaultBranch}}{{end}}
3838
git add README.md
3939
git commit -m "first commit"
40-
git remote add origin <span class="clone-url"></span>
40+
git remote add origin <span class="js-clone-url">{{$.CloneButtonOriginLink.HTTPS}}</span>
4141
git push -u origin {{.Repository.DefaultBranch}}</code></pre>
4242
</div>
4343
</div>
@@ -46,24 +46,11 @@ git push -u origin {{.Repository.DefaultBranch}}</code></pre>
4646
<div class="item">
4747
<h3>{{.i18n.Tr "repo.push_exist_repo"}}</h3>
4848
<div class="markup">
49-
<pre><code>git remote add origin <span class="clone-url"></span>
49+
<pre><code>git remote add origin <span class="js-clone-url">{{$.CloneButtonOriginLink.HTTPS}}</span>
5050
git push -u origin {{.Repository.DefaultBranch}}</code></pre>
5151
</div>
5252
</div>
53-
<!-- the clone-url content will be updated by initRepoCloneLink, the code below is used to avoid UI flicking -->
54-
<script>
55-
(() => {
56-
const proto = localStorage.getItem('repo-clone-protocol') || 'https';
57-
const btn = document.getElementById(`repo-clone-${proto}`);
58-
const cloneUrls = document.getElementsByClassName('clone-url');
59-
// it's ok if we didn't find the btn here, initRepoCloneLink will take all the work
60-
if (btn) {
61-
for (let i = 0; i < cloneUrls.length; i++) {
62-
cloneUrls[i].textContent = btn.getAttribute('data-link');
63-
}
64-
}
65-
})();
66-
</script>
53+
{{template "repo/clone_script" .}}
6754
{{end}}
6855
{{else}}
6956
<div class="ui segment center">

templates/repo/home.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
{{if eq $n 0}}
132132
<div class="ui action tiny input" id="clone-panel">
133133
{{template "repo/clone_buttons" .}}
134+
{{template "repo/clone_script" .}}
134135
<button id="download-btn" class="ui basic jump dropdown icon button tooltip" data-content="{{.i18n.Tr "repo.download_archive"}}" data-position="top right">
135136
{{svg "octicon-download"}}
136137
<div class="menu">

templates/repo/issue/view_content/pull.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@
358358
'emptyCommit': {{.Issue.PullRequest.IsEmpty}},
359359
'pullHeadCommitID': {{.PullHeadCommitID}},
360360
'isPullBranchDeletable': {{.IsPullBranchDeletable}},
361+
'defaultMergeStyle': {{.MergeStyle}},
361362
'defaultDeleteBranchAfterMerge': {{$prUnit.PullRequestsConfig.DefaultDeleteBranchAfterMerge}},
362363
'mergeMessageFieldPlaceHolder': {{$.i18n.Tr "repo.editor.commit_message_desc"}},
363364

templates/repo/wiki/revision.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<div class="ui eight wide column text right df ac je">
88
<div class="ui action small input" id="clone-panel">
99
{{template "repo/clone_buttons" .}}
10+
{{template "repo/clone_script" .}}
1011
</div>
1112
</div>
1213
<div class="ui header eight wide column">

templates/repo/wiki/view.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<div class="right fitted item">
3232
<div class="ui action small input" id="clone-panel">
3333
{{template "repo/clone_buttons" .}}
34+
{{template "repo/clone_script" .}}
3435
</div>
3536
</div>
3637
</div>

templates/shared/issuelist.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@
8585
{{svg "octicon-milestone" 14 "mr-2"}}{{.Milestone.Name}}
8686
</a>
8787
{{end}}
88+
{{if .Project}}
89+
<a class="project" {{if $.RepoLink}}href="{{$.RepoLink}}/projects/{{.Project.ID}}"{{else}}href="{{.Repo.Link}}/projects/{{.Project.ID}}"{{end}}>
90+
{{svg "octicon-project" 14 "mr-2"}}{{.Project.Title}}
91+
</a>
92+
{{end}}
8893
{{if .Ref}}
8994
<a class="ref" {{if $.RepoLink}}href="{{index $.IssueRefURLs .ID}}"{{else}}href="{{.Repo.Link}}{{index $.IssueRefURLs .ID}}"{{end}}>
9095
{{svg "octicon-git-branch" 14 "mr-2"}}{{index $.IssueRefEndNames .ID}}

web_src/js/components/PullRequestMergeForm.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ export default {
145145
146146
created() {
147147
this.mergeStyleAllowedCount = this.mergeForm.mergeStyles.reduce((v, msd) => v + (msd.allowed ? 1 : 0), 0);
148-
this.switchMergeStyle(this.mergeForm.mergeStyles.find((e) => e.allowed)?.name, !this.mergeForm.canMergeNow);
148+
149+
let mergeStyle = this.mergeForm.mergeStyles.find((e) => e.allowed && e.name === this.mergeForm.defaultMergeStyle)?.name;
150+
if (!mergeStyle) mergeStyle = this.mergeForm.mergeStyles.find((e) => e.allowed)?.name;
151+
this.switchMergeStyle(mergeStyle, !this.mergeForm.canMergeNow);
149152
},
150153
151154
mounted() {

web_src/js/features/repo-common.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ export function initRepoArchiveLinks() {
4444
}
4545

4646
export function initRepoCloneLink() {
47-
const defaultGitProtocol = 'https'; // ssh or https
48-
4947
const $repoCloneSsh = $('#repo-clone-ssh');
5048
const $repoCloneHttps = $('#repo-clone-https');
5149
const $inputLink = $('#repo-clone-url');
@@ -54,41 +52,19 @@ export function initRepoCloneLink() {
5452
return;
5553
}
5654

57-
const updateUi = () => {
58-
let isSSH = (localStorage.getItem('repo-clone-protocol') || defaultGitProtocol) === 'ssh';
59-
// there must be at least one clone button (by context/repo.go). if no ssh, then there must be https.
60-
if (isSSH && $repoCloneSsh.length === 0) {
61-
isSSH = false;
62-
} else if (!isSSH && $repoCloneHttps.length === 0) {
63-
isSSH = true;
64-
}
65-
const cloneLink = (isSSH ? $repoCloneSsh : $repoCloneHttps).attr('data-link');
66-
$inputLink.val(cloneLink);
67-
if (isSSH) {
68-
$repoCloneSsh.addClass('primary');
69-
$repoCloneHttps.removeClass('primary');
70-
} else {
71-
$repoCloneSsh.removeClass('primary');
72-
$repoCloneHttps.addClass('primary');
73-
}
74-
// the empty repo guide
75-
$('.quickstart .empty-repo-guide .clone-url').text(cloneLink);
76-
};
77-
updateUi();
78-
55+
// restore animation after first init
7956
setTimeout(() => {
80-
// restore animation after first init
8157
$repoCloneSsh.removeClass('no-transition');
8258
$repoCloneHttps.removeClass('no-transition');
8359
}, 100);
8460

8561
$repoCloneSsh.on('click', () => {
8662
localStorage.setItem('repo-clone-protocol', 'ssh');
87-
updateUi();
63+
window.updateCloneStates();
8864
});
8965
$repoCloneHttps.on('click', () => {
9066
localStorage.setItem('repo-clone-protocol', 'https');
91-
updateUi();
67+
window.updateCloneStates();
9268
});
9369

9470
$inputLink.on('click', () => {

web_src/less/shared/issuelist.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
padding-left: 5px;
102102
}
103103

104-
a.milestone {
104+
a.milestone,
105+
a.project {
105106
margin-left: 5px;
106107
}
107108

0 commit comments

Comments
 (0)