Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* giteaofficial/main:
  Use neutral language in comments and docs (go-gitea#20135)
  Fix remove file on initial comment (go-gitea#20127)
  Add doctor command to write commit-graphs (go-gitea#20007)
  Add sitemap support (go-gitea#18407)
  Use new config options (go-gitea#20125)
  Remove depricated queue indexer usage (go-gitea#20124)
  Disable status checks in template if none found (go-gitea#20088)
  Fix typos related to ErrTaskDoesNotExist error (go-gitea#20118)
  • Loading branch information
zjjhot committed Jun 26, 2022
2 parents 2dbef35 + 711cbcc commit e4b7cf7
Show file tree
Hide file tree
Showing 27 changed files with 372 additions and 26 deletions.
3 changes: 3 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,9 @@ PATH =
;; Number of items that are displayed in home feed
;FEED_PAGING_NUM = 20
;;
;; Number of items that are displayed in a single subsitemap
;SITEMAP_PAGING_NUM = 20
;;
;; Number of maximum commits displayed in commit graph.
;GRAPH_MAX_COMMIT_NUM = 100
;;
Expand Down
1 change: 1 addition & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a
- `MEMBERS_PAGING_NUM`: **20**: Number of members that are shown in organization members.
- `FEED_MAX_COMMIT_NUM`: **5**: Number of maximum commits shown in one activity feed.
- `FEED_PAGING_NUM`: **20**: Number of items that are displayed in home feed.
- `SITEMAP_PAGING_NUM`: **20**: Number of items that are displayed in a single subsitemap.
- `GRAPH_MAX_COMMIT_NUM`: **100**: Number of maximum commits shown in the commit graph.
- `CODE_COMMENT_LINES`: **4**: Number of line of codes shown for a code comment.
- `DEFAULT_THEME`: **auto**: \[auto, gitea, arc-green\]: Set the default theme for the Gitea install.
Expand Down
4 changes: 2 additions & 2 deletions docs/content/doc/developers/oauth2-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ To use the Authorization Code Grant as a third party application it is required

## Scopes

Currently Gitea does not support scopes (see [#4300](https://github.com/go-gitea/gitea/issues/4300)) and all third party applications will be granted access to all resources of the user and his/her organizations.
Currently Gitea does not support scopes (see [#4300](https://github.com/go-gitea/gitea/issues/4300)) and all third party applications will be granted access to all resources of the user and their organizations.

## Example

**Note:** This example does not use PKCE.

1. Redirect to user to the authorization endpoint in order to get his/her consent for accessing the resources:
1. Redirect to user to the authorization endpoint in order to get their consent for accessing the resources:

```curl
https://[YOUR-GITEA-URL]/login/oauth/authorize?client_id=CLIENT_ID&redirect_uri=REDIRECT_URI& response_type=code&state=STATE
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/developers/oauth2-provider.zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Gitea 支援作為 OAuth2 提供者,能讓第三方程式能在使用者同意
**備註:** 此範例未使用 PKCE。

1. 重新導向使用者到 authorization endpoint 以獲得他同意授權存取資源:
<!-- 1. Redirect to user to the authorization endpoint in order to get his/her consent for accessing the resources: -->
<!-- 1. Redirect to user to the authorization endpoint in order to get their consent for accessing the resources: -->

```curl
https://[YOUR-GITEA-URL]/login/oauth/authorize?client_id=CLIENT_ID&redirect_uri=REDIRECT_URI& response_type=code&state=STATE
Expand Down
6 changes: 4 additions & 2 deletions integrations/mssql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ PASSWD = {{TEST_MSSQL_PASSWORD}}
SSL_MODE = disable

[indexer]
ISSUE_INDEXER_PATH = integrations/gitea-integration-mssql/indexers/issues.bleve
ISSUE_INDEXER_QUEUE_DIR = integrations/gitea-integration-mssql/indexers/issues.queue
REPO_INDEXER_ENABLED = true
REPO_INDEXER_PATH = integrations/gitea-integration-mssql/indexers/repos.bleve

[queue.issue_indexer]
PATH = integrations/gitea-integration-mssql/indexers/issues.bleve
DATADIR = integrations/gitea-integration-mssql/indexers/issues.queue

[queue]
TYPE = immediate

Expand Down
8 changes: 5 additions & 3 deletions integrations/mysql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ PASSWD = {{TEST_MYSQL_PASSWORD}}
SSL_MODE = disable

[indexer]
ISSUE_INDEXER_TYPE = elasticsearch
ISSUE_INDEXER_CONN_STR = http://elastic:changeme@elasticsearch:9200
ISSUE_INDEXER_QUEUE_DIR = integrations/gitea-integration-mysql/indexers/issues.queue
REPO_INDEXER_ENABLED = true
REPO_INDEXER_PATH = integrations/gitea-integration-mysql/indexers/repos.bleve

[queue.issue_indexer]
TYPE = elasticsearch
CONN_STR = http://elastic:changeme@elasticsearch:9200
DATADIR = integrations/gitea-integration-mysql/indexers/issues.queue

[queue]
TYPE = immediate

Expand Down
6 changes: 4 additions & 2 deletions integrations/mysql8.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ PASSWD = {{TEST_MYSQL8_PASSWORD}}
SSL_MODE = disable

[indexer]
ISSUE_INDEXER_PATH = integrations/gitea-integration-mysql8/indexers/issues.bleve
ISSUE_INDEXER_QUEUE_DIR = integrations/gitea-integration-mysql8/indexers/issues.queue
REPO_INDEXER_ENABLED = true
REPO_INDEXER_PATH = integrations/gitea-integration-mysql8/indexers/repos.bleve

[queue.issue_indexer]
PATH = integrations/gitea-integration-mysql8/indexers/issues.bleve
DATADIR = integrations/gitea-integration-mysql8/indexers/issues.queue

[queue]
TYPE = immediate

Expand Down
6 changes: 4 additions & 2 deletions integrations/pgsql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ SCHEMA = {{TEST_PGSQL_SCHEMA}}
SSL_MODE = disable

[indexer]
ISSUE_INDEXER_PATH = integrations/gitea-integration-pgsql/indexers/issues.bleve
ISSUE_INDEXER_QUEUE_DIR = integrations/gitea-integration-pgsql/indexers/issues.queue
REPO_INDEXER_ENABLED = true
REPO_INDEXER_PATH = integrations/gitea-integration-pgsql/indexers/repos.bleve

[queue.issue_indexer]
PATH = integrations/gitea-integration-pgsql/indexers/issues.bleve
DATADIR = integrations/gitea-integration-pgsql/indexers/issues.queue

[queue]
TYPE = immediate

Expand Down
6 changes: 4 additions & 2 deletions integrations/sqlite.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ DB_TYPE = sqlite3
PATH = integrations/gitea-integration-sqlite/gitea.db

[indexer]
ISSUE_INDEXER_PATH = integrations/gitea-integration-sqlite/indexers/issues.bleve
ISSUE_INDEXER_QUEUE_DIR = integrations/gitea-integration-sqlite/indexers/issues.queue
REPO_INDEXER_ENABLED = true
REPO_INDEXER_PATH = integrations/gitea-integration-sqlite/indexers/repos.bleve

[queue.issue_indexer]
PATH = integrations/gitea-integration-sqlite/indexers/issues.bleve
DATADIR = integrations/gitea-integration-sqlite/indexers/issues.queue

[queue]
TYPE = immediate

Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v154.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func addTimeStamps(x *xorm.Engine) error {
return err
}

// Follow represents relations of user and his/her followers.
// Follow represents relations of user and their followers.
type Follow struct {
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
}
Expand Down
2 changes: 1 addition & 1 deletion models/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func removeOrgUser(ctx context.Context, orgID, userID int64) error {
}
}

// Delete member in his/her teams.
// Delete member in their teams.
teams, err := organization.GetUserOrgTeams(ctx, org.ID, userID)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions models/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ type ErrTaskDoesNotExist struct {
Type structs.TaskType
}

// IsErrTaskDoesNotExist checks if an error is a ErrTaskIsNotExist.
// IsErrTaskDoesNotExist checks if an error is a ErrTaskDoesNotExist.
func IsErrTaskDoesNotExist(err error) bool {
_, ok := err.(ErrTaskDoesNotExist)
return ok
}

func (err ErrTaskDoesNotExist) Error() string {
return fmt.Sprintf("task is not exist [id: %d, repo_id: %d, type: %d]",
return fmt.Sprintf("task does not exist [id: %d, repo_id: %d, type: %d]",
err.ID, err.RepoID, err.Type)
}

Expand Down
2 changes: 1 addition & 1 deletion models/user/follow.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"code.gitea.io/gitea/modules/timeutil"
)

// Follow represents relations of user and his/her followers.
// Follow represents relations of user and their followers.
type Follow struct {
ID int64 `xorm:"pk autoincr"`
UserID int64 `xorm:"UNIQUE(follow)"`
Expand Down
4 changes: 2 additions & 2 deletions models/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type User struct {
PasswdHashAlgo string `xorm:"NOT NULL DEFAULT 'argon2'"`

// MustChangePassword is an attribute that determines if a user
// is to change his/her password after registration.
// is to change their password after registration.
MustChangePassword bool `xorm:"NOT NULL DEFAULT false"`

LoginType auth.Type
Expand Down Expand Up @@ -537,7 +537,7 @@ func GetUserSalt() (string, error) {
return hex.EncodeToString(rBytes), nil
}

// NewGhostUser creates and returns a fake user for someone has deleted his/her account.
// NewGhostUser creates and returns a fake user for someone has deleted their account.
func NewGhostUser() *User {
return &User{
ID: -1,
Expand Down
3 changes: 3 additions & 0 deletions modules/doctor/mergebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func iteratePRs(ctx context.Context, repo *repo_model.Repository, each func(*rep
}

func checkPRMergeBase(ctx context.Context, logger log.Logger, autofix bool) error {
if err := git.InitOnceWithSync(ctx); err != nil {
return err
}
numRepos := 0
numPRs := 0
numPRsUpdated := 0
Expand Down
76 changes: 76 additions & 0 deletions modules/doctor/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,75 @@ func checkDaemonExport(ctx context.Context, logger log.Logger, autofix bool) err
return nil
}

func checkCommitGraph(ctx context.Context, logger log.Logger, autofix bool) error {
if err := git.InitOnceWithSync(ctx); err != nil {
return err
}

numRepos := 0
numNeedUpdate := 0
numWritten := 0
if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
numRepos++

commitGraphExists := func() (bool, error) {
// Check commit-graph exists
commitGraphFile := path.Join(repo.RepoPath(), `objects/info/commit-graph`)
isExist, err := util.IsExist(commitGraphFile)
if err != nil {
logger.Error("Unable to check if %s exists. Error: %v", commitGraphFile, err)
return false, err
}

if !isExist {
commitGraphsDir := path.Join(repo.RepoPath(), `objects/info/commit-graphs`)
isExist, err = util.IsExist(commitGraphsDir)
if err != nil {
logger.Error("Unable to check if %s exists. Error: %v", commitGraphsDir, err)
return false, err
}
}
return isExist, nil
}

isExist, err := commitGraphExists()
if err != nil {
return err
}
if !isExist {
numNeedUpdate++
if autofix {
if err := git.WriteCommitGraph(ctx, repo.RepoPath()); err != nil {
logger.Error("Unable to write commit-graph in %s. Error: %v", repo.FullName(), err)
return err
}
isExist, err := commitGraphExists()
if err != nil {
return err
}
if isExist {
numWritten++
logger.Info("Commit-graph written: %s", repo.FullName())
} else {
logger.Warn("No commit-graph written: %s", repo.FullName())
}
}
}
return nil
}); err != nil {
logger.Critical("Unable to checkCommitGraph: %v", err)
return err
}

if autofix {
logger.Info("Wrote commit-graph files for %d of %d repositories.", numWritten, numRepos)
} else {
logger.Info("Checked %d repositories, %d without commit-graphs.", numRepos, numNeedUpdate)
}

return nil
}

func init() {
Register(&Check{
Title: "Check if SCRIPT_TYPE is available",
Expand Down Expand Up @@ -225,4 +294,11 @@ func init() {
Run: checkDaemonExport,
Priority: 8,
})
Register(&Check{
Title: "Check commit-graphs",
Name: "check-commit-graphs",
IsDefault: false,
Run: checkCommitGraph,
Priority: 9,
})
}
2 changes: 2 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ var (
// UI settings
UI = struct {
ExplorePagingNum int
SitemapPagingNum int
IssuePagingNum int
RepoSearchPagingNum int
MembersPagingNum int
Expand Down Expand Up @@ -260,6 +261,7 @@ var (
} `ini:"ui.meta"`
}{
ExplorePagingNum: 20,
SitemapPagingNum: 20,
IssuePagingNum: 10,
RepoSearchPagingNum: 10,
MembersPagingNum: 20,
Expand Down
69 changes: 69 additions & 0 deletions modules/sitemap/sitemap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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 sitemap

import (
"bytes"
"encoding/xml"
"fmt"
"io"
"time"
)

// sitemapFileLimit contains the maximum size of a sitemap file
const sitemapFileLimit = 50 * 1024 * 1024

// Url represents a single sitemap entry
type URL struct {
URL string `xml:"loc"`
LastMod *time.Time `xml:"lastmod,omitempty"`
}

// SitemapUrl represents a sitemap
type Sitemap struct {
XMLName xml.Name
Namespace string `xml:"xmlns,attr"`

URLs []URL `xml:"url"`
}

// NewSitemap creates a sitemap
func NewSitemap() *Sitemap {
return &Sitemap{
XMLName: xml.Name{Local: "urlset"},
Namespace: "http://www.sitemaps.org/schemas/sitemap/0.9",
}
}

// NewSitemap creates a sitemap index.
func NewSitemapIndex() *Sitemap {
return &Sitemap{
XMLName: xml.Name{Local: "sitemapindex"},
Namespace: "http://www.sitemaps.org/schemas/sitemap/0.9",
}
}

// Add adds a URL to the sitemap
func (s *Sitemap) Add(u URL) {
s.URLs = append(s.URLs, u)
}

// Write writes the sitemap to a response
func (s *Sitemap) WriteTo(w io.Writer) (int64, error) {
if len(s.URLs) > 50000 {
return 0, fmt.Errorf("The sitemap contains too many URLs: %d", len(s.URLs))
}
buf := bytes.NewBufferString(xml.Header)
if err := xml.NewEncoder(buf).Encode(s); err != nil {
return 0, err
}
if err := buf.WriteByte('\n'); err != nil {
return 0, err
}
if buf.Len() > sitemapFileLimit {
return 0, fmt.Errorf("The sitemap is too big: %d", buf.Len())
}
return buf.WriteTo(w)
}
Loading

0 comments on commit e4b7cf7

Please sign in to comment.