From fed6bb5cde99fe7fa826c94b72ddf0c0ab4b8431 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Wed, 22 Feb 2023 01:31:17 +0800 Subject: [PATCH] Return empty url for submodule tree entries (#23043) Close #22614. Refer to [Github's API](https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28#get-a-tree), if a tree entry is a submodule, its url will be an empty string. --------- Co-authored-by: delvh Co-authored-by: John Olheiser --- services/repository/files/tree.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/repository/files/tree.go b/services/repository/files/tree.go index 513b8a2274787..1df1cb582ba90 100644 --- a/services/repository/files/tree.go +++ b/services/repository/files/tree.go @@ -86,6 +86,11 @@ func GetTreeBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git if entries[e].IsDir() { copy(treeURL[copyPos:], entries[e].ID.String()) tree.Entries[i].URL = string(treeURL) + } else if entries[e].IsSubModule() { + // In Github Rest API Version=2022-11-28, if a tree entry is a submodule, + // its url will be returned as an empty string. + // So the URL will be set to "" here. + tree.Entries[i].URL = "" } else { copy(blobURL[copyPos:], entries[e].ID.String()) tree.Entries[i].URL = string(blobURL)