Skip to content

Commit 14655d8

Browse files
authored
Merge branch 'main' into improve-action-fe
2 parents 632e5e1 + dad057b commit 14655d8

File tree

37 files changed

+1061
-342
lines changed

37 files changed

+1061
-342
lines changed

.drone.yml

Lines changed: 336 additions & 126 deletions
Large diffs are not rendered by default.

.stylelintrc.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
plugins:
22
- stylelint-declaration-strict-value
33

4+
ignoreFiles:
5+
- "**/*.go"
6+
47
overrides:
58
- files: ["**/*.less"]
69
customSyntax: postcss-less
710
- files: ["**/chroma/*", "**/codemirror/*", "**/standalone/*", "**/console/*"]
811
rules:
912
scale-unlimited/declaration-strict-value: null
13+
- files: ["**/chroma/*", "**/codemirror/*"]
14+
rules:
15+
block-no-empty: null
1016

1117
rules:
1218
alpha-value-notation: null

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ help:
190190
@echo " - deps install dependencies"
191191
@echo " - deps-frontend install frontend dependencies"
192192
@echo " - deps-backend install backend dependencies"
193+
@echo " - deps-tools install tool dependencies"
193194
@echo " - lint lint everything"
194195
@echo " - lint-frontend lint frontend files"
195196
@echo " - lint-backend lint backend files"
@@ -821,14 +822,17 @@ docs:
821822
cd docs; make trans-copy clean build-offline;
822823

823824
.PHONY: deps
824-
deps: deps-frontend deps-backend
825+
deps: deps-frontend deps-backend deps-tools
825826

826827
.PHONY: deps-frontend
827828
deps-frontend: node_modules
828829

829830
.PHONY: deps-backend
830831
deps-backend:
831832
$(GO) mod download
833+
834+
.PHONY: deps-tools
835+
deps-tools:
832836
$(GO) install $(AIR_PACKAGE)
833837
$(GO) install $(EDITORCONFIG_CHECKER_PACKAGE)
834838
$(GO) install $(ERRCHECK_PACKAGE)

cmd/admin.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package cmd
77
import (
88
"errors"
99
"fmt"
10+
"net/url"
1011
"os"
1112
"strings"
1213
"text/tabwriter"
@@ -469,11 +470,19 @@ func runAddOauth(c *cli.Context) error {
469470
return err
470471
}
471472

473+
config := parseOAuth2Config(c)
474+
if config.Provider == "openidConnect" {
475+
discoveryURL, err := url.Parse(config.OpenIDConnectAutoDiscoveryURL)
476+
if err != nil || (discoveryURL.Scheme != "http" && discoveryURL.Scheme != "https") {
477+
return fmt.Errorf("invalid Auto Discovery URL: %s (this must be a valid URL starting with http:// or https://)", config.OpenIDConnectAutoDiscoveryURL)
478+
}
479+
}
480+
472481
return auth_model.CreateSource(&auth_model.Source{
473482
Type: auth_model.OAuth2,
474483
Name: c.String("name"),
475484
IsActive: true,
476-
Cfg: parseOAuth2Config(c),
485+
Cfg: config,
477486
})
478487
}
479488

contrib/init/ubuntu/gitea

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/sh
2+
### BEGIN INIT INFO
3+
# Provides: gitea
4+
# Required-Start: $syslog $network
5+
# Required-Stop: $syslog
6+
# Default-Start: 2 3 4 5
7+
# Default-Stop: 0 1 6
8+
# Short-Description: A self-hosted Git service written in Go.
9+
# Description: A self-hosted Git service written in Go.
10+
### END INIT INFO
11+
12+
# Do NOT "set -e"
13+
14+
# PATH should only include /usr/* if it runs after the mountnfs.sh script
15+
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
16+
DESC="Gitea - Git with a cup of tea"
17+
NAME=gitea
18+
SERVICEVERBOSE=yes
19+
PIDFILE=/run/$NAME.pid
20+
SCRIPTNAME=/etc/init.d/$NAME
21+
WORKINGDIR=/var/lib/$NAME
22+
DAEMON=/usr/local/bin/$NAME
23+
DAEMON_ARGS="web -c /etc/$NAME/app.ini"
24+
USER=git
25+
STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/1/KILL/5}"
26+
27+
# Read configuration variable file if it is present
28+
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
29+
30+
# Exit if the package is not installed
31+
[ -x "$DAEMON" ] || exit 0
32+
33+
do_start()
34+
{
35+
GITEA_ENVS="USER=$USER GITEA_WORK_DIR=$WORKINGDIR HOME=/home/$USER"
36+
GITEA_EXEC="$DAEMON -- $DAEMON_ARGS"
37+
sh -c "start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\
38+
--background --chdir $WORKINGDIR --chuid $USER \\
39+
--exec /bin/bash -- -c '/usr/bin/env $GITEA_ENVS $GITEA_EXEC'"
40+
}
41+
42+
do_stop()
43+
{
44+
start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PIDFILE --name $NAME --oknodo
45+
rm -f $PIDFILE
46+
}
47+
48+
do_status()
49+
{
50+
if [ -f $PIDFILE ]; then
51+
if kill -0 $(cat "$PIDFILE"); then
52+
echo "$NAME is running, PID is $(cat $PIDFILE)"
53+
else
54+
echo "$NAME process is dead, but pidfile exists"
55+
fi
56+
else
57+
echo "$NAME is not running"
58+
fi
59+
}
60+
61+
case "$1" in
62+
start)
63+
echo "Starting $DESC" "$NAME"
64+
do_start
65+
;;
66+
stop)
67+
echo "Stopping $DESC" "$NAME"
68+
do_stop
69+
;;
70+
status)
71+
do_status
72+
;;
73+
restart)
74+
echo "Restarting $DESC" "$NAME"
75+
do_stop
76+
do_start
77+
;;
78+
*)
79+
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
80+
exit 2
81+
;;
82+
esac
83+
84+
exit 0

docs/content/doc/packages/maven.en-us.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Publish [Maven](https://maven.apache.org) packages for your user or organization
2323
## Requirements
2424

2525
To work with the Maven package registry, you can use [Maven](https://maven.apache.org/install.html) or [Gradle](https://gradle.org/install/).
26-
The following examples use `Maven`.
26+
The following examples use `Maven` and `Gradle Groovy`.
2727

2828
## Configuring the package registry
2929

@@ -73,6 +73,40 @@ Afterwards add the following sections to your project `pom.xml` file:
7373
| `access_token` | Your [personal access token]({{< relref "doc/developers/api-usage.en-us.md#authentication" >}}). |
7474
| `owner` | The owner of the package. |
7575

76+
### Gradle variant
77+
78+
When you plan to add some packages from Gitea instance in your project, you should add it in repositories section:
79+
80+
```groovy
81+
repositories {
82+
// other repositories
83+
maven { url "https://gitea.example.com/api/packages/{owner}/maven" }
84+
}
85+
```
86+
87+
In Groovy gradle you may include next script in your publishing part:
88+
89+
```groovy
90+
publishing {
91+
// other settings of publication
92+
repositories {
93+
maven {
94+
name = "Gitea"
95+
url = uri("https://gitea.example.com/api/packages/{owner}/maven")
96+
97+
credentials(HttpHeaderCredentials) {
98+
name = "Authorization"
99+
value = "token {access_token}"
100+
}
101+
102+
authentication {
103+
header(HttpHeaderAuthentication)
104+
}
105+
}
106+
}
107+
}
108+
```
109+
76110
## Publish a package
77111

78112
To publish a package simply run:
@@ -81,6 +115,12 @@ To publish a package simply run:
81115
mvn deploy
82116
```
83117

118+
Or call `gradle` with task `publishAllPublicationsToGiteaRepository` in case you are using gradle:
119+
120+
```groovy
121+
./gradlew publishAllPublicationsToGiteaRepository
122+
```
123+
84124
If you want to publish a prebuild package to the registry, you can use [`mvn deploy:deploy-file`](https://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html):
85125

86126
```shell
@@ -105,6 +145,12 @@ To install a Maven package from the package registry, add a new dependency to yo
105145
</dependency>
106146
```
107147

148+
And analog in gradle groovy:
149+
150+
```groovy
151+
implementation "com.test.package:test_project:1.0.0"
152+
```
153+
108154
Afterwards run:
109155

110156
```shell

modules/git/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (c *Command) AddDashesAndList(list ...string) *Command {
179179
}
180180

181181
// ToTrustedCmdArgs converts a list of strings (trusted as argument) to TrustedCmdArgs
182-
// In most cases, it shouldn't be used. Use AddXxx function instead
182+
// In most cases, it shouldn't be used. Use NewCommand().AddXxx() function instead
183183
func ToTrustedCmdArgs(args []string) TrustedCmdArgs {
184184
ret := make(TrustedCmdArgs, len(args))
185185
for i, arg := range args {

modules/git/commit.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,19 @@ func (c *Commit) HasPreviousCommit(commitHash SHA1) (bool, error) {
218218
return false, err
219219
}
220220

221+
// IsForcePush returns true if a push from oldCommitHash to this is a force push
222+
func (c *Commit) IsForcePush(oldCommitID string) (bool, error) {
223+
if oldCommitID == EmptySHA {
224+
return false, nil
225+
}
226+
oldCommit, err := c.repo.GetCommit(oldCommitID)
227+
if err != nil {
228+
return false, err
229+
}
230+
hasPreviousCommit, err := c.HasPreviousCommit(oldCommit.ID)
231+
return !hasPreviousCommit, err
232+
}
233+
221234
// CommitsBeforeLimit returns num commits before current revision
222235
func (c *Commit) CommitsBeforeLimit(num int) ([]*Commit, error) {
223236
return c.repo.getCommitsBeforeLimit(c.ID, num)

modules/git/repo_commit.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,27 @@ func (repo *Repository) CommitsBetweenLimit(last, before *Commit, limit, skip in
323323
return repo.parsePrettyFormatLogToList(bytes.TrimSpace(stdout))
324324
}
325325

326+
// CommitsBetweenNotBase returns a list that contains commits between [before, last), excluding commits in baseBranch.
327+
// If before is detached (removed by reset + push) it is not included.
328+
func (repo *Repository) CommitsBetweenNotBase(last, before *Commit, baseBranch string) ([]*Commit, error) {
329+
var stdout []byte
330+
var err error
331+
if before == nil {
332+
stdout, _, err = NewCommand(repo.Ctx, "rev-list").AddDynamicArguments(last.ID.String()).AddOptionValues("--not", baseBranch).RunStdBytes(&RunOpts{Dir: repo.Path})
333+
} else {
334+
stdout, _, err = NewCommand(repo.Ctx, "rev-list").AddDynamicArguments(before.ID.String()+".."+last.ID.String()).AddOptionValues("--not", baseBranch).RunStdBytes(&RunOpts{Dir: repo.Path})
335+
if err != nil && strings.Contains(err.Error(), "no merge base") {
336+
// future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
337+
// previously it would return the results of git rev-list before last so let's try that...
338+
stdout, _, err = NewCommand(repo.Ctx, "rev-list").AddDynamicArguments(before.ID.String(), last.ID.String()).AddOptionValues("--not", baseBranch).RunStdBytes(&RunOpts{Dir: repo.Path})
339+
}
340+
}
341+
if err != nil {
342+
return nil, err
343+
}
344+
return repo.parsePrettyFormatLogToList(bytes.TrimSpace(stdout))
345+
}
346+
326347
// CommitsBetweenIDs return commits between twoe commits
327348
func (repo *Repository) CommitsBetweenIDs(last, before string) ([]*Commit, error) {
328349
lastCommit, err := repo.GetCommit(last)

modules/repository/push.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
package repository
55

66
import (
7-
"context"
87
"strings"
98

10-
repo_model "code.gitea.io/gitea/models/repo"
119
"code.gitea.io/gitea/modules/git"
1210
)
1311

@@ -96,19 +94,3 @@ func (opts *PushUpdateOptions) RefName() string {
9694
func (opts *PushUpdateOptions) RepoFullName() string {
9795
return opts.RepoUserName + "/" + opts.RepoName
9896
}
99-
100-
// IsForcePush detect if a push is a force push
101-
func IsForcePush(ctx context.Context, opts *PushUpdateOptions) (bool, error) {
102-
if !opts.IsUpdateBranch() {
103-
return false, nil
104-
}
105-
106-
output, _, err := git.NewCommand(ctx, "rev-list", "--max-count=1").AddDynamicArguments(opts.OldCommitID, "^"+opts.NewCommitID).
107-
RunStdString(&git.RunOpts{Dir: repo_model.RepoPath(opts.RepoUserName, opts.RepoName)})
108-
if err != nil {
109-
return false, err
110-
} else if len(output) > 0 {
111-
return true, nil
112-
}
113-
return false, nil
114-
}

0 commit comments

Comments
 (0)