mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	@@ -25,7 +25,7 @@ func TestIterate(t *testing.T) {
 | 
				
			|||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
	assert.EqualValues(t, 79, repoCnt)
 | 
						assert.EqualValues(t, 80, repoCnt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repoUnit *repo_model.RepoUnit) error {
 | 
						err = db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repoUnit *repo_model.RepoUnit) error {
 | 
				
			||||||
		reopUnit2 := repo_model.RepoUnit{ID: repoUnit.ID}
 | 
							reopUnit2 := repo_model.RepoUnit{ID: repoUnit.ID}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -544,3 +544,9 @@
 | 
				
			|||||||
  repo_id: 51
 | 
					  repo_id: 51
 | 
				
			||||||
  type: 2
 | 
					  type: 2
 | 
				
			||||||
  created_unix: 946684810
 | 
					  created_unix: 946684810
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-
 | 
				
			||||||
 | 
					  id: 80
 | 
				
			||||||
 | 
					  repo_id: 53
 | 
				
			||||||
 | 
					  type: 1
 | 
				
			||||||
 | 
					  created_unix: 946684810
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1558,3 +1558,30 @@
 | 
				
			|||||||
  size: 0
 | 
					  size: 0
 | 
				
			||||||
  is_fsck_enabled: true
 | 
					  is_fsck_enabled: true
 | 
				
			||||||
  close_issues_via_commit_in_any_branch: false
 | 
					  close_issues_via_commit_in_any_branch: false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-
 | 
				
			||||||
 | 
					  id: 53
 | 
				
			||||||
 | 
					  owner_id: 30
 | 
				
			||||||
 | 
					  owner_name: user30
 | 
				
			||||||
 | 
					  lower_name: renderer
 | 
				
			||||||
 | 
					  name: renderer
 | 
				
			||||||
 | 
					  is_archived: false
 | 
				
			||||||
 | 
					  is_empty: false
 | 
				
			||||||
 | 
					  is_private: false
 | 
				
			||||||
 | 
					  num_issues: 0
 | 
				
			||||||
 | 
					  num_closed_issues: 0
 | 
				
			||||||
 | 
					  num_pulls: 0
 | 
				
			||||||
 | 
					  num_closed_pulls: 0
 | 
				
			||||||
 | 
					  num_milestones: 0
 | 
				
			||||||
 | 
					  num_closed_milestones: 0
 | 
				
			||||||
 | 
					  num_watches: 0
 | 
				
			||||||
 | 
					  num_projects: 0
 | 
				
			||||||
 | 
					  num_closed_projects: 0
 | 
				
			||||||
 | 
					  status: 0
 | 
				
			||||||
 | 
					  is_fork: false
 | 
				
			||||||
 | 
					  fork_id: 0
 | 
				
			||||||
 | 
					  is_template: false
 | 
				
			||||||
 | 
					  template_id: 0
 | 
				
			||||||
 | 
					  size: 0
 | 
				
			||||||
 | 
					  is_fsck_enabled: true
 | 
				
			||||||
 | 
					  close_issues_via_commit_in_any_branch: false
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1102,7 +1102,7 @@
 | 
				
			|||||||
  num_followers: 0
 | 
					  num_followers: 0
 | 
				
			||||||
  num_following: 0
 | 
					  num_following: 0
 | 
				
			||||||
  num_stars: 0
 | 
					  num_stars: 0
 | 
				
			||||||
  num_repos: 3
 | 
					  num_repos: 4
 | 
				
			||||||
  num_teams: 0
 | 
					  num_teams: 0
 | 
				
			||||||
  num_members: 0
 | 
					  num_members: 0
 | 
				
			||||||
  visibility: 0
 | 
					  visibility: 0
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -235,12 +235,12 @@ func TestSearchRepository(t *testing.T) {
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			name:  "AllPublic/PublicRepositoriesOfUserIncludingCollaborative",
 | 
								name:  "AllPublic/PublicRepositoriesOfUserIncludingCollaborative",
 | 
				
			||||||
			opts:  &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: util.OptionalBoolFalse},
 | 
								opts:  &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: util.OptionalBoolFalse},
 | 
				
			||||||
			count: 28,
 | 
								count: 29,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name:  "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
 | 
								name:  "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
 | 
				
			||||||
			opts:  &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse},
 | 
								opts:  &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse},
 | 
				
			||||||
			count: 33,
 | 
								count: 34,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name:  "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
 | 
								name:  "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
 | 
				
			||||||
@@ -255,7 +255,7 @@ func TestSearchRepository(t *testing.T) {
 | 
				
			|||||||
		{
 | 
							{
 | 
				
			||||||
			name:  "AllPublic/PublicRepositoriesOfOrganization",
 | 
								name:  "AllPublic/PublicRepositoriesOfOrganization",
 | 
				
			||||||
			opts:  &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: util.OptionalBoolFalse, Template: util.OptionalBoolFalse},
 | 
								opts:  &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: util.OptionalBoolFalse, Template: util.OptionalBoolFalse},
 | 
				
			||||||
			count: 28,
 | 
								count: 29,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name:  "AllTemplates",
 | 
								name:  "AllTemplates",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,7 +26,7 @@ func TestArchivedIssues(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Assume: User 30 has access to two Repos with Issues, one of the Repos being archived.
 | 
						// Assume: User 30 has access to two Repos with Issues, one of the Repos being archived.
 | 
				
			||||||
	repos, _, _ := repo_model.GetUserRepositories(&repo_model.SearchRepoOptions{Actor: ctx.Doer})
 | 
						repos, _, _ := repo_model.GetUserRepositories(&repo_model.SearchRepoOptions{Actor: ctx.Doer})
 | 
				
			||||||
	assert.Len(t, repos, 2)
 | 
						assert.Len(t, repos, 3)
 | 
				
			||||||
	IsArchived := make(map[int64]bool)
 | 
						IsArchived := make(map[int64]bool)
 | 
				
			||||||
	NumIssues := make(map[int64]int)
 | 
						NumIssues := make(map[int64]int)
 | 
				
			||||||
	for _, repo := range repos {
 | 
						for _, repo := range repos {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										1
									
								
								tests/gitea-repositories-meta/user30/renderer.git/HEAD
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tests/gitea-repositories-meta/user30/renderer.git/HEAD
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					ref: refs/heads/master
 | 
				
			||||||
							
								
								
									
										6
									
								
								tests/gitea-repositories-meta/user30/renderer.git/config
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								tests/gitea-repositories-meta/user30/renderer.git/config
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					[core]
 | 
				
			||||||
 | 
						repositoryformatversion = 0
 | 
				
			||||||
 | 
						filemode = true
 | 
				
			||||||
 | 
						bare = true
 | 
				
			||||||
 | 
						ignorecase = true
 | 
				
			||||||
 | 
						precomposeunicode = true
 | 
				
			||||||
@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					The repository will be used to test third-party renderer in TestExternalMarkupRenderer
 | 
				
			||||||
@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					data=$(cat)
 | 
				
			||||||
 | 
					exitcodes=""
 | 
				
			||||||
 | 
					hookname=$(basename $0)
 | 
				
			||||||
 | 
					GIT_DIR=${GIT_DIR:-$(dirname $0)}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do
 | 
				
			||||||
 | 
					test -x "${hook}" && test -f "${hook}" || continue
 | 
				
			||||||
 | 
					echo "${data}" | "${hook}"
 | 
				
			||||||
 | 
					exitcodes="${exitcodes} $?"
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for i in ${exitcodes}; do
 | 
				
			||||||
 | 
					[ ${i} -eq 0 ] || exit ${i}
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" post-receive
 | 
				
			||||||
@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					data=$(cat)
 | 
				
			||||||
 | 
					exitcodes=""
 | 
				
			||||||
 | 
					hookname=$(basename $0)
 | 
				
			||||||
 | 
					GIT_DIR=${GIT_DIR:-$(dirname $0)}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do
 | 
				
			||||||
 | 
					test -x "${hook}" && test -f "${hook}" || continue
 | 
				
			||||||
 | 
					echo "${data}" | "${hook}"
 | 
				
			||||||
 | 
					exitcodes="${exitcodes} $?"
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for i in ${exitcodes}; do
 | 
				
			||||||
 | 
					[ ${i} -eq 0 ] || exit ${i}
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" pre-receive
 | 
				
			||||||
@@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					exitcodes=""
 | 
				
			||||||
 | 
					hookname=$(basename $0)
 | 
				
			||||||
 | 
					GIT_DIR=${GIT_DIR:-$(dirname $0)}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do
 | 
				
			||||||
 | 
					test -x "${hook}" && test -f "${hook}" || continue
 | 
				
			||||||
 | 
					"${hook}" $1 $2 $3
 | 
				
			||||||
 | 
					exitcodes="${exitcodes} $?"
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for i in ${exitcodes}; do
 | 
				
			||||||
 | 
					[ ${i} -eq 0 ] || exit ${i}
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" update $1 $2 $3
 | 
				
			||||||
@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					# git ls-files --others --exclude-from=.git/info/exclude
 | 
				
			||||||
 | 
					# Lines that start with '#' are comments.
 | 
				
			||||||
 | 
					# For a project mostly in C, the following would be a good set of
 | 
				
			||||||
 | 
					# exclude patterns (uncomment them if you want to use them):
 | 
				
			||||||
 | 
					# *.[oa]
 | 
				
			||||||
 | 
					# *~
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					# pack-refs with: peeled fully-peeled sorted 
 | 
				
			||||||
 | 
					c961cc4d1ba6b7ee1ba228a9a02b00b7746d8033 refs/heads/master
 | 
				
			||||||
@@ -81,9 +81,9 @@ func TestAPISearchRepo(t *testing.T) {
 | 
				
			|||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{
 | 
								name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{
 | 
				
			||||||
				nil:   {count: 30},
 | 
									nil:   {count: 31},
 | 
				
			||||||
				user:  {count: 30},
 | 
									user:  {count: 31},
 | 
				
			||||||
				user2: {count: 30},
 | 
									user2: {count: 31},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										40
									
								
								tests/integration/markup_external_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								tests/integration/markup_external_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
				
			|||||||
 | 
					// Copyright 2022 The Gitea Authors. All rights reserved.
 | 
				
			||||||
 | 
					// Use of this source code is governed by a MIT-style
 | 
				
			||||||
 | 
					// license that can be found in the LICENSE file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package integration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"code.gitea.io/gitea/modules/setting"
 | 
				
			||||||
 | 
						"code.gitea.io/gitea/tests"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/stretchr/testify/assert"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestExternalMarkupRenderer(t *testing.T) {
 | 
				
			||||||
 | 
						defer tests.PrepareTestEnv(t)()
 | 
				
			||||||
 | 
						if !setting.Database.UseSQLite3 {
 | 
				
			||||||
 | 
							t.Skip()
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const repoURL = "user30/renderer"
 | 
				
			||||||
 | 
						req := NewRequest(t, "GET", repoURL+"/src/branch/master/README.html")
 | 
				
			||||||
 | 
						resp := MakeRequest(t, req, http.StatusOK)
 | 
				
			||||||
 | 
						assert.EqualValues(t, "text/html; charset=UTF-8", resp.Header()["Content-Type"][0])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bs, err := io.ReadAll(resp.Body)
 | 
				
			||||||
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						doc := NewHTMLParser(t, bytes.NewBuffer(bs))
 | 
				
			||||||
 | 
						div := doc.Find("div.file-view")
 | 
				
			||||||
 | 
						data, err := div.Html()
 | 
				
			||||||
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						assert.EqualValues(t, "<div>\n\ttest external renderer\n</div>", strings.TrimSpace(data))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -107,3 +107,10 @@ PATH = tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-sqlite/data/lfs
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
[packages]
 | 
					[packages]
 | 
				
			||||||
ENABLED = true
 | 
					ENABLED = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[markup.html]
 | 
				
			||||||
 | 
					ENABLED = true
 | 
				
			||||||
 | 
					FILE_EXTENSIONS = .html
 | 
				
			||||||
 | 
					RENDER_COMMAND = `go run tools/external_renderer.go`
 | 
				
			||||||
 | 
					IS_INPUT_FILE = false
 | 
				
			||||||
 | 
					RENDER_CONTENT_MODE=sanitized
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										23
									
								
								tools/external_renderer.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								tools/external_renderer.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					// Copyright 2017 The Gitea Authors. All rights reserved.
 | 
				
			||||||
 | 
					// SPDX-License-Identifier: MIT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// gobuild: external_renderer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func main() {
 | 
				
			||||||
 | 
						if len(os.Args) > 1 {
 | 
				
			||||||
 | 
							fmt.Print(os.Args[1])
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							_, err := io.Copy(os.Stdout, os.Stdin)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								fmt.Println(err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user