Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5d238da

Browse files
committedJan 13, 2022
Merge remote-tracking branch 'giteaoffical/main'
* giteaoffical/main: Fix documents for development and bug report (go-gitea#18249) Add/update SMTP auth providers via cli (go-gitea#18197) Fix NPE on try to get tag reference via API (go-gitea#18245) Fix update user bug (go-gitea#18250)
2 parents 67ca2a5 + eaf09a5 commit 5d238da

File tree

16 files changed

+243
-41
lines changed

16 files changed

+243
-41
lines changed
 

‎.github/ISSUE_TEMPLATE/bug-report.yaml

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Bug Report
2-
description: Found something you weren't expecting? Report it here!
2+
description: Found something you weren't expecting? Report it here!
33
body:
44
- type: markdown
55
attributes:
@@ -11,15 +11,16 @@ body:
1111
1. Please speak English, this is the language all maintainers can speak and write.
1212
2. Please ask questions or configuration/deploy problems on our Discord
1313
server (https://discord.gg/gitea) or forum (https://discourse.gitea.io).
14-
3. Please take a moment to check that your issue doesn't already exist.
14+
3. Make sure you are using the latest release and
15+
take a moment to check that your issue hasn't been reported before.
1516
4. Make sure it's not mentioned in the FAQ (https://docs.gitea.io/en-us/faq)
1617
5. Please give all relevant information below for bug reports, because
1718
incomplete details will be handled as an invalid report.
1819
- type: input
1920
id: gitea-ver
2021
attributes:
2122
label: Gitea Version
22-
description: Gitea version (or commit reference) your instance is running
23+
description: Gitea version (or commit reference) of your instance
2324
validations:
2425
required: true
2526
- type: input
@@ -37,8 +38,8 @@ body:
3738
attributes:
3839
label: How are you running Gitea?
3940
description: |
40-
Please include information on whether you built gitea yourself, used one of our downloads, are using https://try.gitea.io or are using some other package
41-
Please also tell us how you are running gitea, e.g. if it is being run from docker, a command-line, systemd etc.
41+
Please include information on whether you built Gitea yourself, used one of our downloads, are using https://try.gitea.io or are using some other package
42+
Please also tell us how you are running Gitea, e.g. if it is being run from docker, a command-line, systemd etc.
4243
If you are using a package or systemd tell us what distribution you are using
4344
validations:
4445
required: true
@@ -67,7 +68,7 @@ body:
6768
- type: markdown
6869
attributes:
6970
value: |
70-
It really is important to provide pertinent logs
71+
It's really important to provide pertinent logs
7172
Please read https://docs.gitea.io/en-us/logging-configuration/#debugging-problems
7273
In addition, if your problem relates to git commands set `RUN_MODE=dev` at the top of app.ini
7374
- type: input
@@ -81,9 +82,9 @@ body:
8182
label: Description
8283
description: |
8384
Please provide a description of your issue here, with a URL if you were able to reproduce the issue (see above)
84-
If using a proxy or a CDN (e.g. CloudFlare) in front of gitea, please disable the proxy/CDN fully and connect to gitea directly to confirm the issue still persists without those services.
85+
If you are using a proxy or a CDN (e.g. Cloudflare) in front of Gitea, please disable the proxy/CDN fully and access Gitea directly to confirm the issue still persists without those services.
8586
- type: textarea
8687
id: screenshots
8788
attributes:
8889
label: Screenshots
89-
description: If this issue involves the Web Interface, please provide a screenshot or multiple screenshots
90+
description: If this issue involves the Web Interface, please provide one or more screenshots

‎Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ clean:
231231

232232
.PHONY: fmt
233233
fmt:
234-
@echo "Running go fmt..."
234+
@echo "Running gitea-fmt(with gofmt)..."
235235
@$(GO) run build/code-batch-process.go gitea-fmt -s -w '{file-list}'
236236

237237
.PHONY: vet
@@ -280,7 +280,7 @@ errcheck:
280280

281281
.PHONY: fmt-check
282282
fmt-check:
283-
# get all go files and run go fmt on them
283+
# get all go files and run gitea-fmt (with gofmt) on them
284284
@diff=$$($(GO) run build/code-batch-process.go gitea-fmt -s -d '{file-list}'); \
285285
if [ -n "$$diff" ]; then \
286286
echo "Please run 'make fmt' and commit the result:"; \

‎build/code-batch-process.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121
)
2222

2323
// Windows has a limitation for command line arguments, the size can not exceed 32KB.
24-
// So we have to feed the files to some tools (like gofmt/misspell`) batch by batch
24+
// So we have to feed the files to some tools (like gofmt/misspell) batch by batch
2525

26-
// We also introduce a `gitea-fmt` command, it does better import formatting than gofmt/goimports
26+
// We also introduce a `gitea-fmt` command, it does better import formatting than gofmt/goimports. `gitea-fmt` calls `gofmt` internally.
2727

2828
var optionLogVerbose bool
2929

‎cmd/admin.go

+181
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"code.gitea.io/gitea/modules/storage"
2828
auth_service "code.gitea.io/gitea/services/auth"
2929
"code.gitea.io/gitea/services/auth/source/oauth2"
30+
"code.gitea.io/gitea/services/auth/source/smtp"
3031
repo_service "code.gitea.io/gitea/services/repository"
3132
user_service "code.gitea.io/gitea/services/user"
3233

@@ -190,6 +191,8 @@ var (
190191
cmdAuthUpdateLdapBindDn,
191192
cmdAuthAddLdapSimpleAuth,
192193
cmdAuthUpdateLdapSimpleAuth,
194+
microcmdAuthAddSMTP,
195+
microcmdAuthUpdateSMTP,
193196
microcmdAuthList,
194197
microcmdAuthDelete,
195198
},
@@ -366,6 +369,72 @@ var (
366369
},
367370
},
368371
}
372+
373+
smtpCLIFlags = []cli.Flag{
374+
cli.StringFlag{
375+
Name: "name",
376+
Value: "",
377+
Usage: "Application Name",
378+
},
379+
cli.StringFlag{
380+
Name: "auth-type",
381+
Value: "PLAIN",
382+
Usage: "SMTP Authentication Type (PLAIN/LOGIN/CRAM-MD5) default PLAIN",
383+
},
384+
cli.StringFlag{
385+
Name: "host",
386+
Value: "",
387+
Usage: "SMTP Host",
388+
},
389+
cli.IntFlag{
390+
Name: "port",
391+
Usage: "SMTP Port",
392+
},
393+
cli.BoolTFlag{
394+
Name: "force-smtps",
395+
Usage: "SMTPS is always used on port 465. Set this to force SMTPS on other ports.",
396+
},
397+
cli.BoolTFlag{
398+
Name: "skip-verify",
399+
Usage: "Skip TLS verify.",
400+
},
401+
cli.StringFlag{
402+
Name: "helo-hostname",
403+
Value: "",
404+
Usage: "Hostname sent with HELO. Leave blank to send current hostname",
405+
},
406+
cli.BoolTFlag{
407+
Name: "disable-helo",
408+
Usage: "Disable SMTP helo.",
409+
},
410+
cli.StringFlag{
411+
Name: "allowed-domains",
412+
Value: "",
413+
Usage: "Leave empty to allow all domains. Separate multiple domains with a comma (',')",
414+
},
415+
cli.BoolTFlag{
416+
Name: "skip-local-2fa",
417+
Usage: "Skip 2FA to log on.",
418+
},
419+
cli.BoolTFlag{
420+
Name: "active",
421+
Usage: "This Authentication Source is Activated.",
422+
},
423+
}
424+
425+
microcmdAuthAddSMTP = cli.Command{
426+
Name: "add-smtp",
427+
Usage: "Add new SMTP authentication source",
428+
Action: runAddSMTP,
429+
Flags: smtpCLIFlags,
430+
}
431+
432+
microcmdAuthUpdateSMTP = cli.Command{
433+
Name: "update-smtp",
434+
Usage: "Update existing SMTP authentication source",
435+
Action: runUpdateSMTP,
436+
Flags: append(smtpCLIFlags[:1], append([]cli.Flag{idFlag}, smtpCLIFlags[1:]...)...),
437+
}
369438
)
370439

371440
func runChangePassword(c *cli.Context) error {
@@ -804,6 +873,118 @@ func runUpdateOauth(c *cli.Context) error {
804873
return auth.UpdateSource(source)
805874
}
806875

876+
func parseSMTPConfig(c *cli.Context, conf *smtp.Source) error {
877+
if c.IsSet("auth-type") {
878+
conf.Auth = c.String("auth-type")
879+
validAuthTypes := []string{"PLAIN", "LOGIN", "CRAM-MD5"}
880+
if !contains(validAuthTypes, strings.ToUpper(c.String("auth-type"))) {
881+
return errors.New("Auth must be one of PLAIN/LOGIN/CRAM-MD5")
882+
}
883+
conf.Auth = c.String("auth-type")
884+
}
885+
if c.IsSet("host") {
886+
conf.Host = c.String("host")
887+
}
888+
if c.IsSet("port") {
889+
conf.Port = c.Int("port")
890+
}
891+
if c.IsSet("allowed-domains") {
892+
conf.AllowedDomains = c.String("allowed-domains")
893+
}
894+
if c.IsSet("force-smtps") {
895+
conf.ForceSMTPS = c.BoolT("force-smtps")
896+
}
897+
if c.IsSet("skip-verify") {
898+
conf.SkipVerify = c.BoolT("skip-verify")
899+
}
900+
if c.IsSet("helo-hostname") {
901+
conf.HeloHostname = c.String("helo-hostname")
902+
}
903+
if c.IsSet("disable-helo") {
904+
conf.DisableHelo = c.BoolT("disable-helo")
905+
}
906+
if c.IsSet("skip-local-2fa") {
907+
conf.SkipLocalTwoFA = c.BoolT("skip-local-2fa")
908+
}
909+
return nil
910+
}
911+
912+
func runAddSMTP(c *cli.Context) error {
913+
ctx, cancel := installSignals()
914+
defer cancel()
915+
916+
if err := initDB(ctx); err != nil {
917+
return err
918+
}
919+
920+
if !c.IsSet("name") || len(c.String("name")) == 0 {
921+
return errors.New("name must be set")
922+
}
923+
if !c.IsSet("host") || len(c.String("host")) == 0 {
924+
return errors.New("host must be set")
925+
}
926+
if !c.IsSet("port") {
927+
return errors.New("port must be set")
928+
}
929+
var active = true
930+
if c.IsSet("active") {
931+
active = c.BoolT("active")
932+
}
933+
934+
var smtpConfig smtp.Source
935+
if err := parseSMTPConfig(c, &smtpConfig); err != nil {
936+
return err
937+
}
938+
939+
// If not set default to PLAIN
940+
if len(smtpConfig.Auth) == 0 {
941+
smtpConfig.Auth = "PLAIN"
942+
}
943+
944+
return auth.CreateSource(&auth.Source{
945+
Type: auth.SMTP,
946+
Name: c.String("name"),
947+
IsActive: active,
948+
Cfg: &smtpConfig,
949+
})
950+
}
951+
952+
func runUpdateSMTP(c *cli.Context) error {
953+
if !c.IsSet("id") {
954+
return fmt.Errorf("--id flag is missing")
955+
}
956+
957+
ctx, cancel := installSignals()
958+
defer cancel()
959+
960+
if err := initDB(ctx); err != nil {
961+
return err
962+
}
963+
964+
source, err := auth.GetSourceByID(c.Int64("id"))
965+
if err != nil {
966+
return err
967+
}
968+
969+
smtpConfig := source.Cfg.(*smtp.Source)
970+
971+
if err := parseSMTPConfig(c, smtpConfig); err != nil {
972+
return err
973+
}
974+
975+
if c.IsSet("name") {
976+
source.Name = c.String("name")
977+
}
978+
979+
if c.IsSet("active") {
980+
source.IsActive = c.BoolT("active")
981+
}
982+
983+
source.Cfg = smtpConfig
984+
985+
return auth.UpdateSource(source)
986+
}
987+
807988
func runListAuth(c *cli.Context) error {
808989
ctx, cancel := installSignals()
809990
defer cancel()

‎docs/content/doc/developers/hacking-on-gitea.en-us.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ required to build the JavaScript and CSS files. The minimum supported Node.js
2929
version is {{< min-node-version >}} and the latest LTS version is recommended.
3030

3131
**Note**: When executing make tasks that require external tools, like
32-
`make misspell-check`, Gitea will automatically download and build these as
32+
`make watch-backend`, Gitea will automatically download and build these as
3333
necessary. To be able to use these you must have the `"$GOPATH"/bin` directory
3434
on the executable path. If you don't add the go bin directory to the
3535
executable path you will have to manage this yourself.
3636

37-
**Note 2**: Go version {{< min-go-version >}} or higher is required; however, it is important
38-
to note that our continuous integration will check that the formatting of the
39-
source code is not changed by `gofmt` using `make fmt-check`. Unfortunately,
40-
the results of `gofmt` can differ by the version of `go`. It is therefore
37+
**Note 2**: Go version {{< min-go-version >}} or higher is required.
38+
Gitea uses `gofmt` to format source code. However, the results of
39+
`gofmt` can differ by the version of `go`. Therefore it is
4140
recommended to install the version of Go that our continuous integration is
42-
running. As of last update, it should be Go version {{< go-version >}}.
41+
running. As of last update, the Go version should be {{< go-version >}}.
4342

4443
## Installing Make
4544

@@ -149,25 +148,26 @@ On macOS, watching all backend source files may hit the default open files limit
149148

150149
### Formatting, code analysis and spell check
151150

152-
Our continuous integration will reject PRs that are not properly formatted, fail
153-
code analysis or spell check.
151+
Our continuous integration will reject PRs that fail the code linters (including format check, code analysis and spell check).
154152

155-
You should format your code with `go fmt` using:
153+
You should format your code:
156154

157155
```bash
158156
make fmt
159157
```
160158

161-
and can test whether your changes would match the results with:
159+
and lint the source code:
162160

163161
```bash
164-
make fmt-check # which runs make fmt internally
162+
# lint both frontend and backend code
163+
make lint
164+
# lint only backend code
165+
make lint-backend
165166
```
166167

167-
**Note**: The results of `go fmt` are dependent on the version of `go` present.
168+
**Note**: The results of `gofmt` are dependent on the version of `go` present.
168169
You should run the same version of go that is on the continuous integration
169-
server as mentioned above. `make fmt-check` will only check if your `go` would
170-
format differently - this may be different from the CI server version.
170+
server as mentioned above.
171171

172172
### Working on JS and CSS
173173

‎docs/content/doc/usage/command-line.en-us.md

+27
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,33 @@ Admin operations:
161161
- `--restricted-group`: Group Claim value for restricted users. (Optional)
162162
- Examples:
163163
- `gitea admin auth update-oauth --id 1 --name external-github-updated`
164+
- `add-smtp`:
165+
- Options:
166+
- `--name`: Application Name. Required.
167+
- `--auth-type`: SMTP Authentication Type (PLAIN/LOGIN/CRAM-MD5). Default to PLAIN.
168+
- `--host`: SMTP host. Required.
169+
- `--port`: SMTP port. Required.
170+
- `--force-smtps`: SMTPS is always used on port 465. Set this to force SMTPS on other ports.
171+
- `--skip-verify`: Skip TLS verify.
172+
- `--helo-hostname`: Hostname sent with HELO. Leave blank to send current hostname.
173+
- `--disable-helo`: Disable SMTP helo.
174+
- `--allowed-domains`: Leave empty to allow all domains. Separate multiple domains with a comma (',').
175+
- `--skip-local-2fa`: Skip 2FA to log on.
176+
- `--active`: This Authentication Source is Activated.
177+
Remarks:
178+
`--force-smtps`, `--skip-verify`, `--disable-helo`, `--skip-loca-2fs` and `--active` options can be used in form:
179+
- `--option`, `--option=true` to enable
180+
- `--option=false` to disable
181+
If those options are not specified value would not be changed in `update-smtp` or would use default `false` value in `add-smtp`
182+
- Examples:
183+
- `gitea admin auth add-smtp --name ldap --host smtp.mydomain.org --port 587 --skip-verify --active`
184+
- `update-smtp`:
185+
- Options:
186+
- `--id`: ID of source to be updated. Required.
187+
- other options are shared with `add-smtp`
188+
- Examples:
189+
- `gitea admin auth update-smtp --id 1 --host smtp.mydomain.org --port 587 --skip-verify=false`
190+
- `gitea admin auth update-smtp --id 1 --active=false`
164191
- `add-ldap`: Add new LDAP (via Bind DN) authentication source
165192
- Options:
166193
- `--name value`: Authentication name. Required.

‎models/user/user.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ func updateUser(ctx context.Context, u *User, changePrimaryEmail bool) error {
855855
if _, err := e.Insert(&emailAddress); err != nil {
856856
return err
857857
}
858-
} else if _, err := e.ID(emailAddress).Cols("is_primary").Update(&EmailAddress{
858+
} else if _, err := e.ID(emailAddress.ID).Cols("is_primary").Update(&EmailAddress{
859859
IsPrimary: true,
860860
}); err != nil {
861861
return err

‎modules/git/repo_commit_nogogit.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ func (repo *Repository) getCommitFromBatchReader(rd *bufio.Reader, id SHA1) (*Co
103103
if err != nil {
104104
return nil, err
105105
}
106-
tag.repo = repo
107106

108-
commit, err := tag.Commit()
107+
commit, err := tag.Commit(repo)
109108
if err != nil {
110109
return nil, err
111110
}

‎modules/git/repo_tag.go

-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ func (repo *Repository) getTag(tagID SHA1, name string) (*Tag, error) {
7272
Type: tp,
7373
Tagger: commit.Committer,
7474
Message: commit.Message(),
75-
repo: repo,
7675
}
7776

7877
repo.tagCache.Set(tagID.String(), tag)
@@ -92,7 +91,6 @@ func (repo *Repository) getTag(tagID SHA1, name string) (*Tag, error) {
9291

9392
tag.Name = name
9493
tag.ID = tagID
95-
tag.repo = repo
9694
tag.Type = tp
9795

9896
repo.tagCache.Set(tagID.String(), tag)

‎modules/git/repo_tag_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ func TestRepository_GetTag(t *testing.T) {
5555
if lTag == nil {
5656
assert.FailNow(t, "nil lTag: %s", lTagName)
5757
}
58-
lTag.repo = nil
5958
assert.EqualValues(t, lTagName, lTag.Name)
6059
assert.EqualValues(t, lTagCommitID, lTag.ID.String())
6160
assert.EqualValues(t, lTagCommitID, lTag.Object.String())

‎modules/git/repo_tree_nogogit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (repo *Repository) getTree(id SHA1) (*Tree, error) {
3434
if err != nil {
3535
return nil, err
3636
}
37-
commit, err := tag.Commit()
37+
commit, err := tag.Commit(repo)
3838
if err != nil {
3939
return nil, err
4040
}

‎modules/git/tag.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const endpgp = "\n-----END PGP SIGNATURE-----"
1717
type Tag struct {
1818
Name string
1919
ID SHA1
20-
repo *Repository
2120
Object SHA1 // The id of this commit object
2221
Type string
2322
Tagger *Signature
@@ -26,8 +25,8 @@ type Tag struct {
2625
}
2726

2827
// Commit return the commit of the tag reference
29-
func (tag *Tag) Commit() (*Commit, error) {
30-
return tag.repo.getCommit(tag.Object)
28+
func (tag *Tag) Commit(gitRepo *Repository) (*Commit, error) {
29+
return gitRepo.getCommit(tag.Object)
3130
}
3231

3332
// Parse commit information from the (uncompressed) raw

‎modules/git/tag_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ tagger Lucas Michot <lucas@semalead.com> 1484491741 +0100
2424
`), tag: Tag{
2525
Name: "",
2626
ID: SHA1{},
27-
repo: nil,
2827
Object: SHA1{0x3b, 0x11, 0x4a, 0xb8, 0x0, 0xc6, 0x43, 0x2a, 0xd4, 0x23, 0x87, 0xcc, 0xf6, 0xbc, 0x8d, 0x43, 0x88, 0xa2, 0x88, 0x5a},
2928
Type: "commit",
3029
Tagger: &Signature{Name: "Lucas Michot", Email: "lucas@semalead.com", When: time.Unix(1484491741, 0)},
@@ -42,7 +41,6 @@ o
4241
ono`), tag: Tag{
4342
Name: "",
4443
ID: SHA1{},
45-
repo: nil,
4644
Object: SHA1{0x7c, 0xdf, 0x42, 0xc0, 0xb1, 0xcc, 0x76, 0x3a, 0xb7, 0xe4, 0xc3, 0x3c, 0x47, 0xa2, 0x4e, 0x27, 0xc6, 0x6b, 0xfc, 0xcc},
4745
Type: "commit",
4846
Tagger: &Signature{Name: "Lucas Michot", Email: "lucas@semalead.com", When: time.Unix(1484553735, 0)},

‎modules/repository/repo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func PushUpdateAddTag(repo *repo_model.Repository, gitRepo *git.Repository, tagN
296296
if err != nil {
297297
return fmt.Errorf("GetTag: %v", err)
298298
}
299-
commit, err := tag.Commit()
299+
commit, err := tag.Commit(gitRepo)
300300
if err != nil {
301301
return fmt.Errorf("Commit: %v", err)
302302
}

‎routers/api/v1/repo/tag.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func GetAnnotatedTag(ctx *context.APIContext) {
103103
if tag, err := ctx.Repo.GitRepo.GetAnnotatedTag(sha); err != nil {
104104
ctx.Error(http.StatusBadRequest, "GetAnnotatedTag", err)
105105
} else {
106-
commit, err := tag.Commit()
106+
commit, err := tag.Commit(ctx.Repo.GitRepo)
107107
if err != nil {
108108
ctx.Error(http.StatusBadRequest, "GetAnnotatedTag", err)
109109
}

‎services/repository/push.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
294294
if err != nil {
295295
return fmt.Errorf("GetTag: %v", err)
296296
}
297-
commit, err := tag.Commit()
297+
commit, err := tag.Commit(gitRepo)
298298
if err != nil {
299299
return fmt.Errorf("Commit: %v", err)
300300
}

0 commit comments

Comments
 (0)
Please sign in to comment.