Skip to content

Commit 30d4a9e

Browse files
authored
Merge branch 'main' into noImplicitAny
2 parents 55ddbea + 2cb3946 commit 30d4a9e

File tree

7 files changed

+54
-27
lines changed

7 files changed

+54
-27
lines changed

options/locale/locale_pt-PT.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,6 @@ pulls.upstream_diverging_prompt_behind_1=Este ramo está %[1]d cometimento atrá
19521952
pulls.upstream_diverging_prompt_behind_n=Este ramo está %[1]d cometimentos atrás de %[2]s
19531953
pulls.upstream_diverging_prompt_base_newer=O ramo base %s tem novas modificações
19541954
pulls.upstream_diverging_merge=Sincronizar derivação
1955-
pulls.upstream_diverging_merge_confirm=Gostaria de integrar o ramo principal do repositório base no ramo %s deste repositório?
19561955

19571956
pull.deleted_branch=(eliminado):%s
19581957
pull.agit_documentation=Rever a documentação sobre o AGit

routers/web/user/home.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -576,17 +576,9 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
576576
// -------------------------------
577577
// Fill stats to post to ctx.Data.
578578
// -------------------------------
579-
issueStats, err := getUserIssueStats(ctx, filterMode, issue_indexer.ToSearchOptions(keyword, opts).Copy(
579+
issueStats, err := getUserIssueStats(ctx, ctxUser, filterMode, issue_indexer.ToSearchOptions(keyword, opts).Copy(
580580
func(o *issue_indexer.SearchOptions) {
581581
o.IsFuzzyKeyword = isFuzzy
582-
// If the doer is the same as the context user, which means the doer is viewing his own dashboard,
583-
// it's not enough to show the repos that the doer owns or has been explicitly granted access to,
584-
// because the doer may create issues or be mentioned in any public repo.
585-
// So we need search issues in all public repos.
586-
o.AllPublic = ctx.Doer.ID == ctxUser.ID
587-
o.MentionID = nil
588-
o.ReviewRequestedID = nil
589-
o.ReviewedID = nil
590582
},
591583
))
592584
if err != nil {
@@ -775,10 +767,19 @@ func UsernameSubRoute(ctx *context.Context) {
775767
}
776768
}
777769

778-
func getUserIssueStats(ctx *context.Context, filterMode int, opts *issue_indexer.SearchOptions) (ret *issues_model.IssueStats, err error) {
770+
func getUserIssueStats(ctx *context.Context, ctxUser *user_model.User, filterMode int, opts *issue_indexer.SearchOptions) (ret *issues_model.IssueStats, err error) {
779771
ret = &issues_model.IssueStats{}
780772
doerID := ctx.Doer.ID
781773

774+
opts = opts.Copy(func(o *issue_indexer.SearchOptions) {
775+
// If the doer is the same as the context user, which means the doer is viewing his own dashboard,
776+
// it's not enough to show the repos that the doer owns or has been explicitly granted access to,
777+
// because the doer may create issues or be mentioned in any public repo.
778+
// So we need search issues in all public repos.
779+
o.AllPublic = doerID == ctxUser.ID
780+
})
781+
782+
// Open/Closed are for the tabs of the issue list
782783
{
783784
openClosedOpts := opts.Copy()
784785
switch filterMode {
@@ -809,6 +810,15 @@ func getUserIssueStats(ctx *context.Context, filterMode int, opts *issue_indexer
809810
}
810811
}
811812

813+
// Below stats are for the left sidebar
814+
opts = opts.Copy(func(o *issue_indexer.SearchOptions) {
815+
o.AssigneeID = nil
816+
o.PosterID = nil
817+
o.MentionID = nil
818+
o.ReviewRequestedID = nil
819+
o.ReviewedID = nil
820+
})
821+
812822
ret.YourRepositoriesCount, err = issue_indexer.CountIssues(ctx, opts.Copy(func(o *issue_indexer.SearchOptions) { o.AllPublic = false }))
813823
if err != nil {
814824
return nil, err

web_src/js/features/comp/EditorMarkdown.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,13 @@ function handleNewline(textarea: HTMLTextAreaElement, e: Event) {
184184
triggerEditorContentChanged(textarea);
185185
}
186186

187+
function isTextExpanderShown(textarea: HTMLElement): boolean {
188+
return Boolean(textarea.closest('text-expander')?.querySelector('.suggestions'));
189+
}
190+
187191
export function initTextareaMarkdown(textarea: HTMLTextAreaElement) {
188192
textarea.addEventListener('keydown', (e) => {
193+
if (isTextExpanderShown(textarea)) return;
189194
if (e.key === 'Tab' && !e.ctrlKey && !e.metaKey && !e.altKey) {
190195
// use Tab/Shift-Tab to indent/unindent the selected lines
191196
handleIndentSelection(textarea, e);

web_src/js/features/comp/TextExpander.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import {matchEmoji, matchMention, matchIssue} from '../../utils/match.ts';
22
import {emojiString} from '../emoji.ts';
33
import {svg} from '../../svg.ts';
4-
import {parseIssueHref, parseIssueNewHref} from '../../utils.ts';
4+
import {parseIssueHref, parseRepoOwnerPathInfo} from '../../utils.ts';
55
import {createElementFromAttrs, createElementFromHTML} from '../../utils/dom.ts';
66
import {getIssueColor, getIssueIcon} from '../issue.ts';
77
import {debounce} from 'perfect-debounce';
88
import type TextExpanderElement from '@github/text-expander-element';
99

1010
const debouncedSuggestIssues = debounce((key: string, text: string) => new Promise<{matched:boolean; fragment?: HTMLElement}>(async (resolve) => {
11-
let issuePathInfo = parseIssueHref(window.location.href);
12-
if (!issuePathInfo.ownerName) issuePathInfo = parseIssueNewHref(window.location.href);
11+
const issuePathInfo = parseIssueHref(window.location.href);
12+
if (!issuePathInfo.ownerName) {
13+
const repoOwnerPathInfo = parseRepoOwnerPathInfo(window.location.pathname);
14+
issuePathInfo.ownerName = repoOwnerPathInfo.ownerName;
15+
issuePathInfo.repoName = repoOwnerPathInfo.repoName;
16+
// then no issuePathInfo.indexString here, it is only used to exclude the current issue when "matchIssue"
17+
}
1318
if (!issuePathInfo.ownerName) return resolve({matched: false});
1419

1520
const matches = await matchIssue(issuePathInfo.ownerName, issuePathInfo.repoName, issuePathInfo.indexString, text);

web_src/js/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export type RequestOpts = {
3232
data?: RequestData,
3333
} & RequestInit;
3434

35+
export type RepoOwnerPathInfo = {
36+
ownerName: string,
37+
repoName: string,
38+
}
39+
3540
export type IssuePathInfo = {
3641
ownerName: string,
3742
repoName: string,

web_src/js/utils.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
basename, extname, isObject, stripTags, parseIssueHref,
33
parseUrl, translateMonth, translateDay, blobToDataURI,
4-
toAbsoluteUrl, encodeURLEncodedBase64, decodeURLEncodedBase64, isImageFile, isVideoFile, parseIssueNewHref,
4+
toAbsoluteUrl, encodeURLEncodedBase64, decodeURLEncodedBase64, isImageFile, isVideoFile, parseRepoOwnerPathInfo,
55
} from './utils.ts';
66

77
test('basename', () => {
@@ -45,12 +45,14 @@ test('parseIssueHref', () => {
4545
expect(parseIssueHref('')).toEqual({ownerName: undefined, repoName: undefined, type: undefined, index: undefined});
4646
});
4747

48-
test('parseIssueNewHref', () => {
49-
expect(parseIssueNewHref('/owner/repo/issues/new')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'issues'});
50-
expect(parseIssueNewHref('/owner/repo/issues/new?query')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'issues'});
51-
expect(parseIssueNewHref('/sub/owner/repo/issues/new#hash')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'issues'});
52-
expect(parseIssueNewHref('/sub/owner/repo/compare/feature/branch-1...fix/branch-2')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'pulls'});
53-
expect(parseIssueNewHref('/other')).toEqual({});
48+
test('parseRepoOwnerPathInfo', () => {
49+
expect(parseRepoOwnerPathInfo('/owner/repo/issues/new')).toEqual({ownerName: 'owner', repoName: 'repo'});
50+
expect(parseRepoOwnerPathInfo('/owner/repo/releases')).toEqual({ownerName: 'owner', repoName: 'repo'});
51+
expect(parseRepoOwnerPathInfo('/other')).toEqual({});
52+
window.config.appSubUrl = '/sub';
53+
expect(parseRepoOwnerPathInfo('/sub/owner/repo/issues/new')).toEqual({ownerName: 'owner', repoName: 'repo'});
54+
expect(parseRepoOwnerPathInfo('/sub/owner/repo/compare/feature/branch-1...fix/branch-2')).toEqual({ownerName: 'owner', repoName: 'repo'});
55+
window.config.appSubUrl = '';
5456
});
5557

5658
test('parseUrl', () => {

web_src/js/utils.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {decode, encode} from 'uint8-to-base64';
2-
import type {IssuePageInfo, IssuePathInfo} from './types.ts';
2+
import type {IssuePageInfo, IssuePathInfo, RepoOwnerPathInfo} from './types.ts';
33

44
// transform /path/to/file.ext to file.ext
55
export function basename(path: string): string {
@@ -32,16 +32,17 @@ export function stripTags(text: string): string {
3232
}
3333

3434
export function parseIssueHref(href: string): IssuePathInfo {
35+
// FIXME: it should use pathname and trim the appSubUrl ahead
3536
const path = (href || '').replace(/[#?].*$/, '');
3637
const [_, ownerName, repoName, pathType, indexString] = /([^/]+)\/([^/]+)\/(issues|pulls)\/([0-9]+)/.exec(path) || [];
3738
return {ownerName, repoName, pathType, indexString};
3839
}
3940

40-
export function parseIssueNewHref(href: string): IssuePathInfo {
41-
const path = (href || '').replace(/[#?].*$/, '');
42-
const [_, ownerName, repoName, pathTypeField] = /([^/]+)\/([^/]+)\/(issues\/new|compare\/.+\.\.\.)/.exec(path) || [];
43-
const pathType = pathTypeField ? (pathTypeField.startsWith('issues/new') ? 'issues' : 'pulls') : undefined;
44-
return {ownerName, repoName, pathType};
41+
export function parseRepoOwnerPathInfo(pathname: string): RepoOwnerPathInfo {
42+
const appSubUrl = window.config.appSubUrl;
43+
if (appSubUrl && pathname.startsWith(appSubUrl)) pathname = pathname.substring(appSubUrl.length);
44+
const [_, ownerName, repoName] = /([^/]+)\/([^/]+)/.exec(pathname) || [];
45+
return {ownerName, repoName};
4546
}
4647

4748
export function parseIssuePageInfo(): IssuePageInfo {

0 commit comments

Comments
 (0)