diff --git a/.golangci.yml b/.golangci.yml
index 17508727650de..37617ad36529d 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -22,6 +22,7 @@ linters:
- typecheck
- unconvert
- unused
+ - unparam
- wastedassign
run:
diff --git a/flake.lock b/flake.lock
index 0b2278f080265..606f8836c1380 100644
--- a/flake.lock
+++ b/flake.lock
@@ -20,11 +20,11 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1715534503,
- "narHash": "sha256-5ZSVkFadZbFP1THataCaSf0JH2cAH3S29hU9rrxTEqk=",
+ "lastModified": 1717974879,
+ "narHash": "sha256-GTO3C88+5DX171F/gVS3Qga/hOs/eRMxPFpiHq2t+D8=",
"owner": "nixos",
"repo": "nixpkgs",
- "rev": "2057814051972fa1453ddfb0d98badbea9b83c06",
+ "rev": "c7b821ba2e1e635ba5a76d299af62821cbcb09f3",
"type": "github"
},
"original": {
diff --git a/flake.nix b/flake.nix
index c6e915e9db4f7..22354663dd5aa 100644
--- a/flake.nix
+++ b/flake.nix
@@ -30,6 +30,7 @@
# backend
go_1_22
+ gofumpt
];
};
}
diff --git a/models/dbfs/dbfile.go b/models/dbfs/dbfile.go
index 3650ce057e4c5..dd27b5c36b798 100644
--- a/models/dbfs/dbfile.go
+++ b/models/dbfs/dbfile.go
@@ -215,16 +215,15 @@ func fileTimestampToTime(timestamp int64) time.Time {
return time.UnixMicro(timestamp)
}
-func (f *file) loadMetaByPath() (*dbfsMeta, error) {
+func (f *file) loadMetaByPath() error {
var fileMeta dbfsMeta
if ok, err := db.GetEngine(f.ctx).Where("full_path = ?", f.fullPath).Get(&fileMeta); err != nil {
- return nil, err
+ return err
} else if ok {
f.metaID = fileMeta.ID
f.blockSize = fileMeta.BlockSize
- return &fileMeta, nil
}
- return nil, nil
+ return nil
}
func (f *file) open(flag int) (err error) {
@@ -288,10 +287,7 @@ func (f *file) createEmpty() error {
if err != nil {
return err
}
- if _, err = f.loadMetaByPath(); err != nil {
- return err
- }
- return nil
+ return f.loadMetaByPath()
}
func (f *file) truncate() error {
@@ -368,8 +364,5 @@ func buildPath(path string) string {
func newDbFile(ctx context.Context, path string) (*file, error) {
path = buildPath(path)
f := &file{ctx: ctx, fullPath: path, blockSize: defaultFileBlockSize}
- if _, err := f.loadMetaByPath(); err != nil {
- return nil, err
- }
- return f, nil
+ return f, f.loadMetaByPath()
}
diff --git a/models/issues/issue_search.go b/models/issues/issue_search.go
index 491def1229153..c1d7d921a9483 100644
--- a/models/issues/issue_search.go
+++ b/models/issues/issue_search.go
@@ -99,9 +99,9 @@ func applySorts(sess *xorm.Session, sortType string, priorityRepoID int64) {
}
}
-func applyLimit(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
+func applyLimit(sess *xorm.Session, opts *IssuesOptions) {
if opts.Paginator == nil || opts.Paginator.IsListAll() {
- return sess
+ return
}
start := 0
@@ -109,11 +109,9 @@ func applyLimit(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
start = (opts.Paginator.Page - 1) * opts.Paginator.PageSize
}
sess.Limit(opts.Paginator.PageSize, start)
-
- return sess
}
-func applyLabelsCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
+func applyLabelsCondition(sess *xorm.Session, opts *IssuesOptions) {
if len(opts.LabelIDs) > 0 {
if opts.LabelIDs[0] == 0 {
sess.Where("issue.id NOT IN (SELECT issue_id FROM issue_label)")
@@ -136,11 +134,9 @@ func applyLabelsCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session
if len(opts.ExcludedLabelNames) > 0 {
sess.And(builder.NotIn("issue.id", BuildLabelNamesIssueIDsCondition(opts.ExcludedLabelNames)))
}
-
- return sess
}
-func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
+func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) {
if len(opts.MilestoneIDs) == 1 && opts.MilestoneIDs[0] == db.NoConditionID {
sess.And("issue.milestone_id = 0")
} else if len(opts.MilestoneIDs) > 0 {
@@ -153,11 +149,9 @@ func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Sess
From("milestone").
Where(builder.In("name", opts.IncludeMilestones)))
}
-
- return sess
}
-func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
+func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) {
if opts.ProjectID > 0 { // specific project
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
And("project_issue.project_id=?", opts.ProjectID)
@@ -166,10 +160,9 @@ func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Sessio
}
// opts.ProjectID == 0 means all projects,
// do not need to apply any condition
- return sess
}
-func applyProjectColumnCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
+func applyProjectColumnCondition(sess *xorm.Session, opts *IssuesOptions) {
// opts.ProjectColumnID == 0 means all project columns,
// do not need to apply any condition
if opts.ProjectColumnID > 0 {
@@ -177,10 +170,9 @@ func applyProjectColumnCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.
} else if opts.ProjectColumnID == db.NoConditionID {
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": 0}))
}
- return sess
}
-func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
+func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) {
if len(opts.RepoIDs) == 1 {
opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoIDs[0]}
} else if len(opts.RepoIDs) > 1 {
@@ -195,10 +187,9 @@ func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session
if opts.RepoCond != nil {
sess.And(opts.RepoCond)
}
- return sess
}
-func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
+func applyConditions(sess *xorm.Session, opts *IssuesOptions) {
if len(opts.IssueIDs) > 0 {
sess.In("issue.id", opts.IssueIDs)
}
@@ -261,8 +252,6 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
if opts.User != nil {
sess.And(issuePullAccessibleRepoCond("issue.repo_id", opts.User.ID, opts.Org, opts.Team, opts.IsPull.Value()))
}
-
- return sess
}
// teamUnitsRepoCond returns query condition for those repo id in the special org team with special units access
@@ -339,22 +328,22 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organizati
return cond
}
-func applyAssigneeCondition(sess *xorm.Session, assigneeID int64) *xorm.Session {
- return sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
+func applyAssigneeCondition(sess *xorm.Session, assigneeID int64) {
+ sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
And("issue_assignees.assignee_id = ?", assigneeID)
}
-func applyPosterCondition(sess *xorm.Session, posterID int64) *xorm.Session {
- return sess.And("issue.poster_id=?", posterID)
+func applyPosterCondition(sess *xorm.Session, posterID int64) {
+ sess.And("issue.poster_id=?", posterID)
}
-func applyMentionedCondition(sess *xorm.Session, mentionedID int64) *xorm.Session {
- return sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
+func applyMentionedCondition(sess *xorm.Session, mentionedID int64) {
+ sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
And("issue_user.is_mentioned = ?", true).
And("issue_user.uid = ?", mentionedID)
}
-func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64) *xorm.Session {
+func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64) {
existInTeamQuery := builder.Select("team_user.team_id").
From("team_user").
Where(builder.Eq{"team_user.uid": reviewRequestedID})
@@ -375,11 +364,11 @@ func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64)
),
builder.In("review.id", maxReview),
))
- return sess.Where("issue.poster_id <> ?", reviewRequestedID).
+ sess.Where("issue.poster_id <> ?", reviewRequestedID).
And(builder.In("issue.id", subQuery))
}
-func applyReviewedCondition(sess *xorm.Session, reviewedID int64) *xorm.Session {
+func applyReviewedCondition(sess *xorm.Session, reviewedID int64) {
// Query for pull requests where you are a reviewer or commenter, excluding
// any pull requests already returned by the review requested filter.
notPoster := builder.Neq{"issue.poster_id": reviewedID}
@@ -406,11 +395,11 @@ func applyReviewedCondition(sess *xorm.Session, reviewedID int64) *xorm.Session
builder.In("type", CommentTypeComment, CommentTypeCode, CommentTypeReview),
)),
)
- return sess.And(notPoster, builder.Or(reviewed, commented))
+ sess.And(notPoster, builder.Or(reviewed, commented))
}
-func applySubscribedCondition(sess *xorm.Session, subscriberID int64) *xorm.Session {
- return sess.And(
+func applySubscribedCondition(sess *xorm.Session, subscriberID int64) {
+ sess.And(
builder.
NotIn("issue.id",
builder.Select("issue_id").
diff --git a/models/issues/pull_list.go b/models/issues/pull_list.go
index e8011a916fb4c..a1d46f8cd425c 100644
--- a/models/issues/pull_list.go
+++ b/models/issues/pull_list.go
@@ -28,7 +28,7 @@ type PullRequestsOptions struct {
MilestoneID int64
}
-func listPullRequestStatement(ctx context.Context, baseRepoID int64, opts *PullRequestsOptions) (*xorm.Session, error) {
+func listPullRequestStatement(ctx context.Context, baseRepoID int64, opts *PullRequestsOptions) *xorm.Session {
sess := db.GetEngine(ctx).Where("pull_request.base_repo_id=?", baseRepoID)
sess.Join("INNER", "issue", "pull_request.issue_id = issue.id")
@@ -46,7 +46,7 @@ func listPullRequestStatement(ctx context.Context, baseRepoID int64, opts *PullR
sess.And("issue.milestone_id=?", opts.MilestoneID)
}
- return sess, nil
+ return sess
}
// GetUnmergedPullRequestsByHeadInfo returns all pull requests that are open and has not been merged
@@ -130,23 +130,15 @@ func PullRequests(ctx context.Context, baseRepoID int64, opts *PullRequestsOptio
opts.Page = 1
}
- countSession, err := listPullRequestStatement(ctx, baseRepoID, opts)
- if err != nil {
- log.Error("listPullRequestStatement: %v", err)
- return nil, 0, err
- }
+ countSession := listPullRequestStatement(ctx, baseRepoID, opts)
maxResults, err := countSession.Count(new(PullRequest))
if err != nil {
log.Error("Count PRs: %v", err)
return nil, maxResults, err
}
- findSession, err := listPullRequestStatement(ctx, baseRepoID, opts)
+ findSession := listPullRequestStatement(ctx, baseRepoID, opts)
applySorts(findSession, opts.SortType, 0)
- if err != nil {
- log.Error("listPullRequestStatement: %v", err)
- return nil, maxResults, err
- }
findSession = db.SetSessionPagination(findSession, opts)
prs := make([]*PullRequest, 0, opts.PageSize)
return prs, maxResults, findSession.Find(&prs)
diff --git a/modules/auth/password/hash/common.go b/modules/auth/password/hash/common.go
index ac6faf35cff96..487c0738f42f4 100644
--- a/modules/auth/password/hash/common.go
+++ b/modules/auth/password/hash/common.go
@@ -18,7 +18,7 @@ func parseIntParam(value, param, algorithmName, config string, previousErr error
return parsed, previousErr // <- Keep the previous error as this function should still return an error once everything has been checked if any call failed
}
-func parseUIntParam(value, param, algorithmName, config string, previousErr error) (uint64, error) {
+func parseUIntParam(value, param, algorithmName, config string, previousErr error) (uint64, error) { //nolint:unparam
parsed, err := strconv.ParseUint(value, 10, 64)
if err != nil {
log.Error("invalid integer for %s representation in %s hash spec %s", param, algorithmName, config)
diff --git a/modules/lfs/http_client.go b/modules/lfs/http_client.go
index e06879baea4fe..f5ddd38b0911d 100644
--- a/modules/lfs/http_client.go
+++ b/modules/lfs/http_client.go
@@ -211,7 +211,7 @@ func createRequest(ctx context.Context, method, url string, headers map[string]s
for key, value := range headers {
req.Header.Set(key, value)
}
- req.Header.Set("Accept", MediaType)
+ req.Header.Set("Accept", AcceptHeader)
return req, nil
}
@@ -251,6 +251,6 @@ func handleErrorResponse(resp *http.Response) error {
return err
}
- log.Trace("ErrorResponse: %v", er)
+ log.Trace("ErrorResponse(%v): %v", resp.Status, er)
return errors.New(er.Message)
}
diff --git a/modules/lfs/http_client_test.go b/modules/lfs/http_client_test.go
index 7459d9c0c97e8..7431132f760f4 100644
--- a/modules/lfs/http_client_test.go
+++ b/modules/lfs/http_client_test.go
@@ -155,7 +155,7 @@ func TestHTTPClientDownload(t *testing.T) {
hc := &http.Client{Transport: RoundTripFunc(func(req *http.Request) *http.Response {
assert.Equal(t, "POST", req.Method)
assert.Equal(t, MediaType, req.Header.Get("Content-type"))
- assert.Equal(t, MediaType, req.Header.Get("Accept"))
+ assert.Equal(t, AcceptHeader, req.Header.Get("Accept"))
var batchRequest BatchRequest
err := json.NewDecoder(req.Body).Decode(&batchRequest)
@@ -263,7 +263,7 @@ func TestHTTPClientUpload(t *testing.T) {
hc := &http.Client{Transport: RoundTripFunc(func(req *http.Request) *http.Response {
assert.Equal(t, "POST", req.Method)
assert.Equal(t, MediaType, req.Header.Get("Content-type"))
- assert.Equal(t, MediaType, req.Header.Get("Accept"))
+ assert.Equal(t, AcceptHeader, req.Header.Get("Accept"))
var batchRequest BatchRequest
err := json.NewDecoder(req.Body).Decode(&batchRequest)
diff --git a/modules/lfs/shared.go b/modules/lfs/shared.go
index 6b2e55f2fbfd3..80f4fed00d406 100644
--- a/modules/lfs/shared.go
+++ b/modules/lfs/shared.go
@@ -10,6 +10,8 @@ import (
const (
// MediaType contains the media type for LFS server requests
MediaType = "application/vnd.git-lfs+json"
+ // Some LFS servers offer content with other types, so fallback to '*/*' if application/vnd.git-lfs+json cannot be served
+ AcceptHeader = "application/vnd.git-lfs+json;q=0.9, */*;q=0.8"
)
// BatchRequest contains multiple requests processed in one batch operation.
diff --git a/modules/lfs/transferadapter.go b/modules/lfs/transferadapter.go
index d425b91946d17..fbc3a3ad8c716 100644
--- a/modules/lfs/transferadapter.go
+++ b/modules/lfs/transferadapter.go
@@ -37,6 +37,7 @@ func (a *BasicTransferAdapter) Download(ctx context.Context, l *Link) (io.ReadCl
if err != nil {
return nil, err
}
+ log.Debug("Download Request: %+v", req)
resp, err := performRequest(ctx, a.client, req)
if err != nil {
return nil, err
diff --git a/modules/lfs/transferadapter_test.go b/modules/lfs/transferadapter_test.go
index 6023cd07d32fd..7fec137efe569 100644
--- a/modules/lfs/transferadapter_test.go
+++ b/modules/lfs/transferadapter_test.go
@@ -26,7 +26,7 @@ func TestBasicTransferAdapter(t *testing.T) {
p := Pointer{Oid: "b5a2c96250612366ea272ffac6d9744aaf4b45aacd96aa7cfcb931ee3b558259", Size: 5}
roundTripHandler := func(req *http.Request) *http.Response {
- assert.Equal(t, MediaType, req.Header.Get("Accept"))
+ assert.Equal(t, AcceptHeader, req.Header.Get("Accept"))
assert.Equal(t, "test-value", req.Header.Get("test-header"))
url := req.URL.String()
diff --git a/modules/packages/cran/metadata.go b/modules/packages/cran/metadata.go
index 24e6f323af888..0b0bfb07c6675 100644
--- a/modules/packages/cran/metadata.go
+++ b/modules/packages/cran/metadata.go
@@ -185,8 +185,6 @@ func ParseDescription(r io.Reader) (*Package, error) {
}
func setField(p *Package, data string) error {
- const listDelimiter = ", "
-
if data == "" {
return nil
}
@@ -215,19 +213,19 @@ func setField(p *Package, data string) error {
case "Description":
p.Metadata.Description = value
case "URL":
- p.Metadata.ProjectURL = splitAndTrim(value, listDelimiter)
+ p.Metadata.ProjectURL = splitAndTrim(value)
case "License":
p.Metadata.License = value
case "Author":
- p.Metadata.Authors = splitAndTrim(authorReplacePattern.ReplaceAllString(value, ""), listDelimiter)
+ p.Metadata.Authors = splitAndTrim(authorReplacePattern.ReplaceAllString(value, ""))
case "Depends":
- p.Metadata.Depends = splitAndTrim(value, listDelimiter)
+ p.Metadata.Depends = splitAndTrim(value)
case "Imports":
- p.Metadata.Imports = splitAndTrim(value, listDelimiter)
+ p.Metadata.Imports = splitAndTrim(value)
case "Suggests":
- p.Metadata.Suggests = splitAndTrim(value, listDelimiter)
+ p.Metadata.Suggests = splitAndTrim(value)
case "LinkingTo":
- p.Metadata.LinkingTo = splitAndTrim(value, listDelimiter)
+ p.Metadata.LinkingTo = splitAndTrim(value)
case "NeedsCompilation":
p.Metadata.NeedsCompilation = value == "yes"
}
@@ -235,8 +233,8 @@ func setField(p *Package, data string) error {
return nil
}
-func splitAndTrim(s, sep string) []string {
- items := strings.Split(s, sep)
+func splitAndTrim(s string) []string {
+ items := strings.Split(s, ", ")
for i := range items {
items[i] = strings.TrimSpace(items[i])
}
diff --git a/modules/setting/config_env.go b/modules/setting/config_env.go
index 242f40914a159..dfcb7db3c8624 100644
--- a/modules/setting/config_env.go
+++ b/modules/setting/config_env.go
@@ -97,7 +97,7 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) {
// decodeEnvironmentKey decode the environment key to section and key
// The environment key is in the form of GITEA__SECTION__KEY or GITEA__SECTION__KEY__FILE
-func decodeEnvironmentKey(prefixGitea, suffixFile, envKey string) (ok bool, section, key string, useFileValue bool) {
+func decodeEnvironmentKey(prefixGitea, suffixFile, envKey string) (ok bool, section, key string, useFileValue bool) { //nolint:unparam
if !strings.HasPrefix(envKey, prefixGitea) {
return false, "", "", false
}
diff --git a/modules/setting/storage.go b/modules/setting/storage.go
index d44c968423f83..d6f7672b613d8 100644
--- a/modules/setting/storage.go
+++ b/modules/setting/storage.go
@@ -161,7 +161,7 @@ const (
targetSecIsSec // target section is from the name seciont [name]
)
-func getStorageSectionByType(rootCfg ConfigProvider, typ string) (ConfigSection, targetSecType, error) {
+func getStorageSectionByType(rootCfg ConfigProvider, typ string) (ConfigSection, targetSecType, error) { //nolint:unparam
targetSec, err := rootCfg.GetSection(storageSectionName + "." + typ)
if err != nil {
if !IsValidStorageType(StorageType(typ)) {
diff --git a/modules/storage/azureblob.go b/modules/storage/azureblob.go
index 52a7d1637e031..211522c5bba2e 100644
--- a/modules/storage/azureblob.go
+++ b/modules/storage/azureblob.go
@@ -163,10 +163,7 @@ func (a *AzureBlobStorage) getObjectNameFromPath(path string) string {
// Open opens a file
func (a *AzureBlobStorage) Open(path string) (Object, error) {
- blobClient, err := a.getBlobClient(path)
- if err != nil {
- return nil, convertAzureBlobErr(err)
- }
+ blobClient := a.getBlobClient(path)
res, err := blobClient.GetProperties(a.ctx, &blob.GetPropertiesOptions{})
if err != nil {
return nil, convertAzureBlobErr(err)
@@ -229,10 +226,7 @@ func (a azureBlobFileInfo) Sys() any {
// Stat returns the stat information of the object
func (a *AzureBlobStorage) Stat(path string) (os.FileInfo, error) {
- blobClient, err := a.getBlobClient(path)
- if err != nil {
- return nil, convertAzureBlobErr(err)
- }
+ blobClient := a.getBlobClient(path)
res, err := blobClient.GetProperties(a.ctx, &blob.GetPropertiesOptions{})
if err != nil {
return nil, convertAzureBlobErr(err)
@@ -247,20 +241,14 @@ func (a *AzureBlobStorage) Stat(path string) (os.FileInfo, error) {
// Delete delete a file
func (a *AzureBlobStorage) Delete(path string) error {
- blobClient, err := a.getBlobClient(path)
- if err != nil {
- return convertAzureBlobErr(err)
- }
- _, err = blobClient.Delete(a.ctx, nil)
+ blobClient := a.getBlobClient(path)
+ _, err := blobClient.Delete(a.ctx, nil)
return convertAzureBlobErr(err)
}
// URL gets the redirect URL to a file. The presigned link is valid for 5 minutes.
func (a *AzureBlobStorage) URL(path, name string) (*url.URL, error) {
- blobClient, err := a.getBlobClient(path)
- if err != nil {
- return nil, convertAzureBlobErr(err)
- }
+ blobClient := a.getBlobClient(path)
startTime := time.Now()
u, err := blobClient.GetSASURL(sas.BlobPermissions{
@@ -290,10 +278,7 @@ func (a *AzureBlobStorage) IterateObjects(dirName string, fn func(path string, o
return convertAzureBlobErr(err)
}
for _, object := range resp.Segment.BlobItems {
- blobClient, err := a.getBlobClient(*object.Name)
- if err != nil {
- return convertAzureBlobErr(err)
- }
+ blobClient := a.getBlobClient(*object.Name)
object := &azureBlobObject{
Context: a.ctx,
blobClient: blobClient,
@@ -313,8 +298,8 @@ func (a *AzureBlobStorage) IterateObjects(dirName string, fn func(path string, o
}
// Delete delete a file
-func (a *AzureBlobStorage) getBlobClient(path string) (*blob.Client, error) {
- return a.client.ServiceClient().NewContainerClient(a.cfg.Container).NewBlobClient(a.buildAzureBlobPath(path)), nil
+func (a *AzureBlobStorage) getBlobClient(path string) *blob.Client {
+ return a.client.ServiceClient().NewContainerClient(a.cfg.Container).NewBlobClient(a.buildAzureBlobPath(path))
}
func init() {
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index 94464fe628b98..330cbf8908b15 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -9,6 +9,7 @@ import (
"html"
"html/template"
"net/url"
+ "reflect"
"slices"
"strings"
"time"
@@ -237,8 +238,8 @@ func DotEscape(raw string) string {
// Iif is an "inline-if", similar util.Iif[T] but templates need the non-generic version,
// and it could be simply used as "{{Iif expr trueVal}}" (omit the falseVal).
-func Iif(condition bool, vals ...any) any {
- if condition {
+func Iif(condition any, vals ...any) any {
+ if isTemplateTruthy(condition) {
return vals[0]
} else if len(vals) > 1 {
return vals[1]
@@ -246,6 +247,32 @@ func Iif(condition bool, vals ...any) any {
return nil
}
+func isTemplateTruthy(v any) bool {
+ if v == nil {
+ return false
+ }
+
+ rv := reflect.ValueOf(v)
+ switch rv.Kind() {
+ case reflect.Bool:
+ return rv.Bool()
+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
+ return rv.Int() != 0
+ case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
+ return rv.Uint() != 0
+ case reflect.Float32, reflect.Float64:
+ return rv.Float() != 0
+ case reflect.Complex64, reflect.Complex128:
+ return rv.Complex() != 0
+ case reflect.String, reflect.Slice, reflect.Array, reflect.Map:
+ return rv.Len() > 0
+ case reflect.Struct:
+ return true
+ default:
+ return !rv.IsNil()
+ }
+}
+
// Eval the expression and return the result, see the comment of eval.Expr for details.
// To use this helper function in templates, pass each token as a separate parameter.
//
diff --git a/modules/templates/helper_test.go b/modules/templates/helper_test.go
index 0cefb7a6b2e0e..ea5da7be80845 100644
--- a/modules/templates/helper_test.go
+++ b/modules/templates/helper_test.go
@@ -5,8 +5,11 @@ package templates
import (
"html/template"
+ "strings"
"testing"
+ "code.gitea.io/gitea/modules/util"
+
"github.com/stretchr/testify/assert"
)
@@ -65,3 +68,41 @@ func TestHTMLFormat(t *testing.T) {
func TestSanitizeHTML(t *testing.T) {
assert.Equal(t, template.HTML(`link xss
inline
`), SanitizeHTML(`link xss inline
`))
}
+
+func TestTemplateTruthy(t *testing.T) {
+ tmpl := template.New("test")
+ tmpl.Funcs(template.FuncMap{"Iif": Iif})
+ template.Must(tmpl.Parse(`{{if .Value}}true{{else}}false{{end}}:{{Iif .Value "true" "false"}}`))
+
+ cases := []any{
+ nil, false, true, "", "string", 0, 1,
+ byte(0), byte(1), int64(0), int64(1), float64(0), float64(1),
+ complex(0, 0), complex(1, 0),
+ (chan int)(nil), make(chan int),
+ (func())(nil), func() {},
+ util.ToPointer(0), util.ToPointer(util.ToPointer(0)),
+ util.ToPointer(1), util.ToPointer(util.ToPointer(1)),
+ [0]int{},
+ [1]int{0},
+ []int(nil),
+ []int{},
+ []int{0},
+ map[any]any(nil),
+ map[any]any{},
+ map[any]any{"k": "v"},
+ (*struct{})(nil),
+ struct{}{},
+ util.ToPointer(struct{}{}),
+ }
+ w := &strings.Builder{}
+ truthyCount := 0
+ for i, v := range cases {
+ w.Reset()
+ assert.NoError(t, tmpl.Execute(w, struct{ Value any }{v}), "case %d (%T) %#v fails", i, v, v)
+ out := w.String()
+ truthyCount += util.Iif(out == "true:true", 1, 0)
+ truthyMatches := out == "true:true" || out == "false:false"
+ assert.True(t, truthyMatches, "case %d (%T) %#v fail: %s", i, v, v, out)
+ }
+ assert.True(t, truthyCount != 0 && truthyCount != len(cases))
+}
diff --git a/modules/util/keypair.go b/modules/util/keypair.go
index 8b86c142af7c3..07f27bd1ba6c4 100644
--- a/modules/util/keypair.go
+++ b/modules/util/keypair.go
@@ -15,10 +15,7 @@ import (
// GenerateKeyPair generates a public and private keypair
func GenerateKeyPair(bits int) (string, string, error) {
priv, _ := rsa.GenerateKey(rand.Reader, bits)
- privPem, err := pemBlockForPriv(priv)
- if err != nil {
- return "", "", err
- }
+ privPem := pemBlockForPriv(priv)
pubPem, err := pemBlockForPub(&priv.PublicKey)
if err != nil {
return "", "", err
@@ -26,12 +23,12 @@ func GenerateKeyPair(bits int) (string, string, error) {
return privPem, pubPem, nil
}
-func pemBlockForPriv(priv *rsa.PrivateKey) (string, error) {
+func pemBlockForPriv(priv *rsa.PrivateKey) string {
privBytes := pem.EncodeToMemory(&pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(priv),
})
- return string(privBytes), nil
+ return string(privBytes)
}
func pemBlockForPub(pub *rsa.PublicKey) (string, error) {
diff --git a/routers/api/actions/artifacts.go b/routers/api/actions/artifacts.go
index 16af957d0f6e4..72a2a26c4761e 100644
--- a/routers/api/actions/artifacts.go
+++ b/routers/api/actions/artifacts.go
@@ -242,16 +242,12 @@ func (ar artifactRoutes) uploadArtifact(ctx *ArtifactContext) {
}
// get upload file size
- fileRealTotalSize, contentLength, err := getUploadFileSize(ctx)
- if err != nil {
- log.Error("Error get upload file size: %v", err)
- ctx.Error(http.StatusInternalServerError, "Error get upload file size")
- return
- }
+ fileRealTotalSize, contentLength := getUploadFileSize(ctx)
// get artifact retention days
expiredDays := setting.Actions.ArtifactRetentionDays
if queryRetentionDays := ctx.Req.URL.Query().Get("retentionDays"); queryRetentionDays != "" {
+ var err error
expiredDays, err = strconv.ParseInt(queryRetentionDays, 10, 64)
if err != nil {
log.Error("Error parse retention days: %v", err)
diff --git a/routers/api/actions/artifacts_utils.go b/routers/api/actions/artifacts_utils.go
index aaf89ef40e6d3..3517d57f7800d 100644
--- a/routers/api/actions/artifacts_utils.go
+++ b/routers/api/actions/artifacts_utils.go
@@ -43,7 +43,7 @@ func validateRunID(ctx *ArtifactContext) (*actions.ActionTask, int64, bool) {
return task, runID, true
}
-func validateRunIDV4(ctx *ArtifactContext, rawRunID string) (*actions.ActionTask, int64, bool) {
+func validateRunIDV4(ctx *ArtifactContext, rawRunID string) (*actions.ActionTask, int64, bool) { //nolint:unparam
task := ctx.ActionTask
runID, err := strconv.ParseInt(rawRunID, 10, 64)
if err != nil || task.Job.RunID != runID {
@@ -84,11 +84,11 @@ func parseArtifactItemPath(ctx *ArtifactContext) (string, string, bool) {
// getUploadFileSize returns the size of the file to be uploaded.
// The raw size is the size of the file as reported by the header X-TFS-FileLength.
-func getUploadFileSize(ctx *ArtifactContext) (int64, int64, error) {
+func getUploadFileSize(ctx *ArtifactContext) (int64, int64) {
contentLength := ctx.Req.ContentLength
xTfsLength, _ := strconv.ParseInt(ctx.Req.Header.Get(artifactXTfsFileLengthHeader), 10, 64)
if xTfsLength > 0 {
- return xTfsLength, contentLength, nil
+ return xTfsLength, contentLength
}
- return contentLength, contentLength, nil
+ return contentLength, contentLength
}
diff --git a/routers/api/packages/container/blob.go b/routers/api/packages/container/blob.go
index f2d63297c1411..9e3a47076c2fa 100644
--- a/routers/api/packages/container/blob.go
+++ b/routers/api/packages/container/blob.go
@@ -26,7 +26,7 @@ var uploadVersionMutex sync.Mutex
// saveAsPackageBlob creates a package blob from an upload
// The uploaded blob gets stored in a special upload version to link them to the package/image
-func saveAsPackageBlob(ctx context.Context, hsr packages_module.HashedSizeReader, pci *packages_service.PackageCreationInfo) (*packages_model.PackageBlob, error) {
+func saveAsPackageBlob(ctx context.Context, hsr packages_module.HashedSizeReader, pci *packages_service.PackageCreationInfo) (*packages_model.PackageBlob, error) { //nolint:unparam
pb := packages_service.NewPackageBlob(hsr)
exists := false
diff --git a/routers/api/packages/nuget/nuget.go b/routers/api/packages/nuget/nuget.go
index 3633d0d00704c..0d7212d7f782f 100644
--- a/routers/api/packages/nuget/nuget.go
+++ b/routers/api/packages/nuget/nuget.go
@@ -36,7 +36,7 @@ func apiError(ctx *context.Context, status int, obj any) {
})
}
-func xmlResponse(ctx *context.Context, status int, obj any) {
+func xmlResponse(ctx *context.Context, status int, obj any) { //nolint:unparam
ctx.Resp.Header().Set("Content-Type", "application/atom+xml; charset=utf-8")
ctx.Resp.WriteHeader(status)
if _, err := ctx.Resp.Write([]byte(xml.Header)); err != nil {
diff --git a/routers/api/v1/repo/compare.go b/routers/api/v1/repo/compare.go
index cfd61d768c507..429145c714800 100644
--- a/routers/api/v1/repo/compare.go
+++ b/routers/api/v1/repo/compare.go
@@ -64,7 +64,7 @@ func CompareDiff(ctx *context.APIContext) {
}
}
- _, _, headGitRepo, ci, _, _ := parseCompareInfo(ctx, api.CreatePullRequestOption{
+ _, headGitRepo, ci, _, _ := parseCompareInfo(ctx, api.CreatePullRequestOption{
Base: infos[0],
Head: infos[1],
})
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 4014fe80f3272..1fc94708daf1b 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -408,7 +408,7 @@ func CreatePullRequest(ctx *context.APIContext) {
)
// Get repo/branch information
- _, headRepo, headGitRepo, compareInfo, baseBranch, headBranch := parseCompareInfo(ctx, form)
+ headRepo, headGitRepo, compareInfo, baseBranch, headBranch := parseCompareInfo(ctx, form)
if ctx.Written() {
return
}
@@ -1054,7 +1054,7 @@ func MergePullRequest(ctx *context.APIContext) {
ctx.Status(http.StatusOK)
}
-func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (*user_model.User, *repo_model.Repository, *git.Repository, *git.CompareInfo, string, string) {
+func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (*repo_model.Repository, *git.Repository, *git.CompareInfo, string, string) {
baseRepo := ctx.Repo.Repository
// Get compared branches information
@@ -1087,14 +1087,14 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
} else {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
}
- return nil, nil, nil, nil, "", ""
+ return nil, nil, nil, "", ""
}
headBranch = headInfos[1]
// The head repository can also point to the same repo
isSameRepo = ctx.Repo.Owner.ID == headUser.ID
} else {
ctx.NotFound()
- return nil, nil, nil, nil, "", ""
+ return nil, nil, nil, "", ""
}
ctx.Repo.PullRequest.SameRepo = isSameRepo
@@ -1102,7 +1102,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
// Check if base branch is valid.
if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) && !ctx.Repo.GitRepo.IsTagExist(baseBranch) {
ctx.NotFound("BaseNotExist")
- return nil, nil, nil, nil, "", ""
+ return nil, nil, nil, "", ""
}
// Check if current user has fork of repository or in the same repository.
@@ -1110,7 +1110,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
if headRepo == nil && !isSameRepo {
log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID)
ctx.NotFound("GetForkedRepo")
- return nil, nil, nil, nil, "", ""
+ return nil, nil, nil, "", ""
}
var headGitRepo *git.Repository
@@ -1121,7 +1121,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
headGitRepo, err = gitrepo.OpenRepository(ctx, headRepo)
if err != nil {
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
- return nil, nil, nil, nil, "", ""
+ return nil, nil, nil, "", ""
}
}
@@ -1130,7 +1130,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
if err != nil {
headGitRepo.Close()
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
- return nil, nil, nil, nil, "", ""
+ return nil, nil, nil, "", ""
}
if !permBase.CanReadIssuesOrPulls(true) || !permBase.CanRead(unit.TypeCode) {
if log.IsTrace() {
@@ -1141,7 +1141,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
}
headGitRepo.Close()
ctx.NotFound("Can't read pulls or can't read UnitTypeCode")
- return nil, nil, nil, nil, "", ""
+ return nil, nil, nil, "", ""
}
// user should have permission to read headrepo's codes
@@ -1149,7 +1149,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
if err != nil {
headGitRepo.Close()
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
- return nil, nil, nil, nil, "", ""
+ return nil, nil, nil, "", ""
}
if !permHead.CanRead(unit.TypeCode) {
if log.IsTrace() {
@@ -1160,24 +1160,24 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
}
headGitRepo.Close()
ctx.NotFound("Can't read headRepo UnitTypeCode")
- return nil, nil, nil, nil, "", ""
+ return nil, nil, nil, "", ""
}
// Check if head branch is valid.
if !headGitRepo.IsBranchExist(headBranch) && !headGitRepo.IsTagExist(headBranch) {
headGitRepo.Close()
ctx.NotFound()
- return nil, nil, nil, nil, "", ""
+ return nil, nil, nil, "", ""
}
compareInfo, err := headGitRepo.GetCompareInfo(repo_model.RepoPath(baseRepo.Owner.Name, baseRepo.Name), baseBranch, headBranch, false, false)
if err != nil {
headGitRepo.Close()
ctx.Error(http.StatusInternalServerError, "GetCompareInfo", err)
- return nil, nil, nil, nil, "", ""
+ return nil, nil, nil, "", ""
}
- return headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch
+ return headRepo, headGitRepo, compareInfo, baseBranch, headBranch
}
// UpdatePullRequest merge PR's baseBranch into headBranch
diff --git a/routers/web/admin/config.go b/routers/web/admin/config.go
index fd8c73b62d8db..2a842cff82b07 100644
--- a/routers/web/admin/config.go
+++ b/routers/web/admin/config.go
@@ -183,7 +183,7 @@ func ChangeConfig(ctx *context.Context) {
value := ctx.FormString("value")
cfg := setting.Config()
- marshalBool := func(v string) (string, error) {
+ marshalBool := func(v string) (string, error) { //nolint:unparam
if b, _ := strconv.ParseBool(v); b {
return "true", nil
}
diff --git a/services/lfs/server.go b/services/lfs/server.go
index 2e330aa1a4865..ae3dffe0c2912 100644
--- a/services/lfs/server.go
+++ b/services/lfs/server.go
@@ -477,7 +477,7 @@ func buildObjectResponse(rc *requestContext, pointer lfs_module.Pointer, downloa
}
// This is only needed to workaround https://github.com/git-lfs/git-lfs/issues/3662
- verifyHeader["Accept"] = lfs_module.MediaType
+ verifyHeader["Accept"] = lfs_module.AcceptHeader
rep.Actions["verify"] = &lfs_module.Link{Href: rc.VerifyLink(pointer), Header: verifyHeader}
}
diff --git a/services/pull/merge.go b/services/pull/merge.go
index 6b5e9ea330559..9ef3fb2e0593a 100644
--- a/services/pull/merge.go
+++ b/services/pull/merge.go
@@ -246,7 +246,7 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
}
// doMergeAndPush performs the merge operation without changing any pull information in database and pushes it up to the base repository
-func doMergeAndPush(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string, pushTrigger repo_module.PushTrigger) (string, error) {
+func doMergeAndPush(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string, pushTrigger repo_module.PushTrigger) (string, error) { //nolint:unparam
// Clone base repo.
mergeCtx, cancel, err := createTemporaryRepoForMerge(ctx, pr, doer, expectedHeadCommitID)
if err != nil {
diff --git a/services/webhook/dingtalk.go b/services/webhook/dingtalk.go
index c57d04415ae5d..f6018f7374cdd 100644
--- a/services/webhook/dingtalk.go
+++ b/services/webhook/dingtalk.go
@@ -190,6 +190,6 @@ type dingtalkConvertor struct{}
var _ payloadConvertor[DingtalkPayload] = dingtalkConvertor{}
-func newDingtalkRequest(ctx context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
+func newDingtalkRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
return newJSONRequest(dingtalkConvertor{}, w, t, true)
}
diff --git a/services/webhook/discord.go b/services/webhook/discord.go
index 3883ac9eb8782..31332396f2cef 100644
--- a/services/webhook/discord.go
+++ b/services/webhook/discord.go
@@ -260,7 +260,7 @@ type discordConvertor struct {
var _ payloadConvertor[DiscordPayload] = discordConvertor{}
-func newDiscordRequest(ctx context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
+func newDiscordRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
meta := &DiscordMeta{}
if err := json.Unmarshal([]byte(w.Meta), meta); err != nil {
return nil, nil, fmt.Errorf("newDiscordRequest meta json: %w", err)
diff --git a/services/webhook/feishu.go b/services/webhook/feishu.go
index 1ec436894b0cc..38f324aa7b5a4 100644
--- a/services/webhook/feishu.go
+++ b/services/webhook/feishu.go
@@ -168,6 +168,6 @@ type feishuConvertor struct{}
var _ payloadConvertor[FeishuPayload] = feishuConvertor{}
-func newFeishuRequest(ctx context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
+func newFeishuRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
return newJSONRequest(feishuConvertor{}, w, t, true)
}
diff --git a/services/webhook/matrix.go b/services/webhook/matrix.go
index 5dcfdcb0ddc3c..e649a0760943a 100644
--- a/services/webhook/matrix.go
+++ b/services/webhook/matrix.go
@@ -24,7 +24,7 @@ import (
webhook_module "code.gitea.io/gitea/modules/webhook"
)
-func newMatrixRequest(ctx context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
+func newMatrixRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
meta := &MatrixMeta{}
if err := json.Unmarshal([]byte(w.Meta), meta); err != nil {
return nil, nil, fmt.Errorf("GetMatrixPayload meta json: %w", err)
diff --git a/services/webhook/msteams.go b/services/webhook/msteams.go
index 99d010618444f..b052b9da100ed 100644
--- a/services/webhook/msteams.go
+++ b/services/webhook/msteams.go
@@ -347,6 +347,6 @@ type msteamsConvertor struct{}
var _ payloadConvertor[MSTeamsPayload] = msteamsConvertor{}
-func newMSTeamsRequest(ctx context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
+func newMSTeamsRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
return newJSONRequest(msteamsConvertor{}, w, t, true)
}
diff --git a/services/webhook/packagist.go b/services/webhook/packagist.go
index 7880d8b606691..593b97a174105 100644
--- a/services/webhook/packagist.go
+++ b/services/webhook/packagist.go
@@ -112,7 +112,7 @@ type packagistConvertor struct {
var _ payloadConvertor[PackagistPayload] = packagistConvertor{}
-func newPackagistRequest(ctx context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
+func newPackagistRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
meta := &PackagistMeta{}
if err := json.Unmarshal([]byte(w.Meta), meta); err != nil {
return nil, nil, fmt.Errorf("newpackagistRequest meta json: %w", err)
diff --git a/services/webhook/slack.go b/services/webhook/slack.go
index ba8bac27d97f3..ffa2936bea74c 100644
--- a/services/webhook/slack.go
+++ b/services/webhook/slack.go
@@ -283,7 +283,7 @@ type slackConvertor struct {
var _ payloadConvertor[SlackPayload] = slackConvertor{}
-func newSlackRequest(ctx context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
+func newSlackRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
meta := &SlackMeta{}
if err := json.Unmarshal([]byte(w.Meta), meta); err != nil {
return nil, nil, fmt.Errorf("newSlackRequest meta json: %w", err)
diff --git a/services/webhook/telegram.go b/services/webhook/telegram.go
index c2b4820032411..de6c878dad64d 100644
--- a/services/webhook/telegram.go
+++ b/services/webhook/telegram.go
@@ -191,6 +191,6 @@ type telegramConvertor struct{}
var _ payloadConvertor[TelegramPayload] = telegramConvertor{}
-func newTelegramRequest(ctx context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
+func newTelegramRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
return newJSONRequest(telegramConvertor{}, w, t, true)
}
diff --git a/services/webhook/wechatwork.go b/services/webhook/wechatwork.go
index 46e7856ecfa5f..2e9d31cb7cef1 100644
--- a/services/webhook/wechatwork.go
+++ b/services/webhook/wechatwork.go
@@ -177,6 +177,6 @@ type wechatworkConvertor struct{}
var _ payloadConvertor[WechatworkPayload] = wechatworkConvertor{}
-func newWechatworkRequest(ctx context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
+func newWechatworkRequest(_ context.Context, w *webhook_model.Webhook, t *webhook_model.HookTask) (*http.Request, []byte, error) {
return newJSONRequest(wechatworkConvertor{}, w, t, true)
}
diff --git a/templates/admin/auth/list.tmpl b/templates/admin/auth/list.tmpl
index 6483ec800c4a1..174dda1e2afd9 100644
--- a/templates/admin/auth/list.tmpl
+++ b/templates/admin/auth/list.tmpl
@@ -25,7 +25,7 @@
{{.ID}} |
{{.Name}} |
{{.TypeName}} |
- {{if .IsActive}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} |
+ {{svg (Iif .IsActive "octicon-check" "octicon-x")}} |
{{DateTime "short" .UpdatedUnix}} |
{{DateTime "short" .CreatedUnix}} |
{{svg "octicon-pencil"}} |
diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl
index 8c16429920ba4..197a6c6add272 100644
--- a/templates/admin/config.tmpl
+++ b/templates/admin/config.tmpl
@@ -16,9 +16,9 @@
{{ctx.Locale.Tr "admin.config.domain"}}
{{.Domain}}
{{ctx.Locale.Tr "admin.config.offline_mode"}}
- {{if .OfflineMode}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ {{svg (Iif .OfflineMode "octicon-check" "octicon-x")}}
{{ctx.Locale.Tr "admin.config.disable_router_log"}}
- {{if .DisableRouterLog}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ {{svg (Iif .DisableRouterLog "octicon-check" "octicon-x")}}
@@ -55,10 +55,10 @@
- {{ctx.Locale.Tr "admin.config.ssh_enabled"}}
- - {{if not .SSH.Disabled}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif (not .SSH.Disabled) "octicon-check" "octicon-x")}}
{{if not .SSH.Disabled}}
- {{ctx.Locale.Tr "admin.config.ssh_start_builtin_server"}}
- - {{if .SSH.StartBuiltinServer}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .SSH.StartBuiltinServer "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.ssh_domain"}}
- {{.SSH.Domain}}
- {{ctx.Locale.Tr "admin.config.ssh_port"}}
@@ -74,7 +74,7 @@
- {{ctx.Locale.Tr "admin.config.ssh_keygen_path"}}
- {{.SSH.KeygenPath}}
- {{ctx.Locale.Tr "admin.config.ssh_minimum_key_size_check"}}
- - {{if .SSH.MinimumKeySizeCheck}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .SSH.MinimumKeySizeCheck "octicon-check" "octicon-x")}}
{{if .SSH.MinimumKeySizeCheck}}
- {{ctx.Locale.Tr "admin.config.ssh_minimum_key_sizes"}}
- {{.SSH.MinimumKeySizes}}
@@ -90,7 +90,7 @@
- {{ctx.Locale.Tr "admin.config.lfs_enabled"}}
- - {{if .LFS.StartServer}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .LFS.StartServer "octicon-check" "octicon-x")}}
{{if .LFS.StartServer}}
- {{ctx.Locale.Tr "admin.config.lfs_content_path"}}
- {{JsonUtils.EncodeToString .LFS.Storage.ToShadowCopy}}
@@ -134,36 +134,36 @@
- {{ctx.Locale.Tr "admin.config.register_email_confirm"}}
- - {{if .Service.RegisterEmailConfirm}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.RegisterEmailConfirm "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.disable_register"}}
- - {{if .Service.DisableRegistration}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.DisableRegistration "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.allow_only_internal_registration"}}
- - {{if .Service.AllowOnlyInternalRegistration}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.AllowOnlyInternalRegistration "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.allow_only_external_registration"}}
- - {{if .Service.AllowOnlyExternalRegistration}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.AllowOnlyExternalRegistration "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.show_registration_button"}}
- - {{if .Service.ShowRegistrationButton}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.ShowRegistrationButton "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.enable_openid_signup"}}
- - {{if .Service.EnableOpenIDSignUp}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.EnableOpenIDSignUp "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.enable_openid_signin"}}
- - {{if .Service.EnableOpenIDSignIn}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.EnableOpenIDSignIn "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.require_sign_in_view"}}
- - {{if .Service.RequireSignInView}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.RequireSignInView "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.mail_notify"}}
- - {{if .Service.EnableNotifyMail}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.EnableNotifyMail "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.enable_captcha"}}
- - {{if .Service.EnableCaptcha}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.EnableCaptcha "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.default_keep_email_private"}}
- - {{if .Service.DefaultKeepEmailPrivate}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.DefaultKeepEmailPrivate "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.default_allow_create_organization"}}
- - {{if .Service.DefaultAllowCreateOrganization}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.DefaultAllowCreateOrganization "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.enable_timetracking"}}
- - {{if .Service.EnableTimetracking}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.EnableTimetracking "octicon-check" "octicon-x")}}
{{if .Service.EnableTimetracking}}
- {{ctx.Locale.Tr "admin.config.default_enable_timetracking"}}
- - {{if .Service.DefaultEnableTimetracking}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.DefaultEnableTimetracking "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.default_allow_only_contributors_to_track_time"}}
- - {{if .Service.DefaultAllowOnlyContributorsToTrackTime}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.DefaultAllowOnlyContributorsToTrackTime "octicon-check" "octicon-x")}}
{{end}}
- {{ctx.Locale.Tr "admin.config.default_visibility_organization"}}
- {{.Service.DefaultOrgVisibility}}
@@ -171,7 +171,7 @@
- {{ctx.Locale.Tr "admin.config.no_reply_address"}}
- {{if .Service.NoReplyAddress}}{{.Service.NoReplyAddress}}{{else}}-{{end}}
- {{ctx.Locale.Tr "admin.config.default_enable_dependencies"}}
- - {{if .Service.DefaultEnableDependencies}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Service.DefaultEnableDependencies "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.active_code_lives"}}
- {{.Service.ActiveCodeLives}} {{ctx.Locale.Tr "tool.raw_minutes"}}
@@ -190,7 +190,7 @@
- {{ctx.Locale.Tr "admin.config.deliver_timeout"}}
- {{.Webhook.DeliverTimeout}} {{ctx.Locale.Tr "tool.raw_seconds"}}
- {{ctx.Locale.Tr "admin.config.skip_tls_verify"}}
- - {{if .Webhook.SkipTLSVerify}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Webhook.SkipTLSVerify "octicon-check" "octicon-x")}}
@@ -200,7 +200,7 @@
- {{ctx.Locale.Tr "admin.config.mailer_enabled"}}
- - {{if .MailerEnabled}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .MailerEnabled "octicon-check" "octicon-x")}}
{{if .MailerEnabled}}
- {{ctx.Locale.Tr "admin.config.mailer_name"}}
- {{.Mailer.Name}}
@@ -220,7 +220,7 @@
- {{ctx.Locale.Tr "admin.config.mailer_protocol"}}
- {{.Mailer.Protocol}}
- {{ctx.Locale.Tr "admin.config.mailer_enable_helo"}}
- - {{if .Mailer.EnableHelo}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Mailer.EnableHelo "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.mailer_smtp_addr"}}
- {{.Mailer.SMTPAddr}}
- {{ctx.Locale.Tr "admin.config.mailer_smtp_port"}}
@@ -279,7 +279,7 @@
- {{ctx.Locale.Tr "admin.config.session_life_time"}}
- {{.SessionConfig.Maxlifetime}} {{ctx.Locale.Tr "tool.raw_seconds"}}
- {{ctx.Locale.Tr "admin.config.https_only"}}
- - {{if .SessionConfig.Secure}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .SessionConfig.Secure "octicon-check" "octicon-x")}}
@@ -289,7 +289,7 @@
- {{ctx.Locale.Tr "admin.config.git_disable_diff_highlight"}}
- - {{if .Git.DisableDiffHighlight}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif .Git.DisableDiffHighlight "octicon-check" "octicon-x")}}
- {{ctx.Locale.Tr "admin.config.git_max_diff_lines"}}
- {{.Git.MaxGitDiffLines}}
- {{ctx.Locale.Tr "admin.config.git_max_diff_line_characters"}}
@@ -321,7 +321,7 @@
{{if .Loggers.xorm.IsEnabled}}
- {{ctx.Locale.Tr "admin.config.xorm_log_sql"}}
- - {{if $.LogSQL}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ - {{svg (Iif $.LogSQL "octicon-check" "octicon-x")}}
{{end}}
{{if .Loggers.access.IsEnabled}}
diff --git a/templates/admin/cron.tmpl b/templates/admin/cron.tmpl
index 3cb641488ccf8..bb412ef146b9a 100644
--- a/templates/admin/cron.tmpl
+++ b/templates/admin/cron.tmpl
@@ -26,7 +26,7 @@
{{DateTime "full" .Next}} |
{{if gt .Prev.Year 1}}{{DateTime "full" .Prev}}{{else}}-{{end}} |
{{.ExecTimes}} |
- {{if eq .Status ""}}—{{else if eq .Status "finished"}}{{svg "octicon-check" 16}}{{else}}{{svg "octicon-x" 16}}{{end}} |
+ {{if eq .Status ""}}—{{else}}{{svg (Iif (eq .Status "finished") "octicon-check" "octicon-x") 16}}{{end}} |
{{end}}
diff --git a/templates/admin/emails/list.tmpl b/templates/admin/emails/list.tmpl
index 388863df9b27d..1f226afcc4ccc 100644
--- a/templates/admin/emails/list.tmpl
+++ b/templates/admin/emails/list.tmpl
@@ -46,17 +46,17 @@
{{.Name}} |
{{.FullName}} |
{{.Email}} |
- {{if .IsPrimary}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} |
+ {{svg (Iif .IsPrimary "octicon-check" "octicon-x")}} |
{{if .CanChange}}
- {{if .IsActivated}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ {{svg (Iif .IsActivated "octicon-check" "octicon-x")}}
{{else}}
- {{if .IsActivated}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}
+ {{svg (Iif .IsActivated "octicon-check" "octicon-x")}}
{{end}}
|
diff --git a/templates/admin/user/list.tmpl b/templates/admin/user/list.tmpl
index 528d047507502..bc54d33431b2e 100644
--- a/templates/admin/user/list.tmpl
+++ b/templates/admin/user/list.tmpl
@@ -93,9 +93,9 @@
{{end}}
{{.Email}} |
- {{if .IsActive}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} |
- {{if .IsRestricted}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} |
- {{if index $.UsersTwoFaStatus .ID}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} |
+ {{svg (Iif .IsActive "octicon-check" "octicon-x")}} |
+ {{svg (Iif .IsRestricted "octicon-check" "octicon-x")}} |
+ {{svg (Iif (index $.UsersTwoFaStatus .ID) "octicon-check" "octicon-x")}} |
{{DateTime "short" .CreatedUnix}} |
{{if .LastLoginUnix}}
{{DateTime "short" .LastLoginUnix}} |
diff --git a/templates/repo/diff/whitespace_dropdown.tmpl b/templates/repo/diff/whitespace_dropdown.tmpl
index c54de165a4c9a..cf695791cadab 100644
--- a/templates/repo/diff/whitespace_dropdown.tmpl
+++ b/templates/repo/diff/whitespace_dropdown.tmpl
@@ -27,4 +27,4 @@
-{{if .IsSplitStyle}}{{svg "gitea-join"}}{{else}}{{svg "gitea-split"}}{{end}}
+{{svg (Iif .IsSplitStyle "gitea-join" "gitea-split")}}
diff --git a/templates/repo/issue/filter_actions.tmpl b/templates/repo/issue/filter_actions.tmpl
index 18986db773b50..88d0653f7db17 100644
--- a/templates/repo/issue/filter_actions.tmpl
+++ b/templates/repo/issue/filter_actions.tmpl
@@ -30,7 +30,7 @@
{{end}}
{{$previousExclusiveScope = $exclusiveScope}}
- {{if SliceUtils.Contains $.SelLabelIDs .ID}}{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}{{end}} {{RenderLabel $.Context ctx.Locale .}}
+ {{if SliceUtils.Contains $.SelLabelIDs .ID}}{{svg (Iif $exclusiveScope "octicon-dot-fill" "octicon-check")}}{{end}} {{RenderLabel $.Context ctx.Locale .}}
{{template "repo/issue/labels/label_archived" .}}
{{end}}
diff --git a/templates/repo/issue/labels/labels_selector_field.tmpl b/templates/repo/issue/labels/labels_selector_field.tmpl
index e5f15caca5a6f..3d65a7d8cd542 100644
--- a/templates/repo/issue/labels/labels_selector_field.tmpl
+++ b/templates/repo/issue/labels/labels_selector_field.tmpl
@@ -21,7 +21,7 @@
{{end}}
{{$previousExclusiveScope = $exclusiveScope}}
- {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}} {{RenderLabel $.Context ctx.Locale .}}
+ {{svg (Iif $exclusiveScope "octicon-dot-fill" "octicon-check")}} {{RenderLabel $.Context ctx.Locale .}}
{{if .Description}}
{{.Description | RenderEmoji $.Context}}{{end}}
{{template "repo/issue/labels/label_archived" .}}
@@ -34,7 +34,7 @@
{{end}}
{{$previousExclusiveScope = $exclusiveScope}}
- {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}} {{RenderLabel $.Context ctx.Locale .}}
+ {{svg (Iif $exclusiveScope "octicon-dot-fill" "octicon-check")}} {{RenderLabel $.Context ctx.Locale .}}
{{if .Description}}
{{.Description | RenderEmoji $.Context}}{{end}}
{{template "repo/issue/labels/label_archived" .}}
diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl
index bb0bb2cff3602..ce34c5e9392ff 100644
--- a/templates/repo/issue/view_content/sidebar.tmpl
+++ b/templates/repo/issue/view_content/sidebar.tmpl
@@ -92,7 +92,7 @@
{{end}}
{{if and .CanChange (or .Checked (and (not $.Issue.IsClosed) (not $.Issue.PullRequest.HasMerged)))}}
- {{if .Checked}}{{svg "octicon-trash"}}{{else}}{{svg "octicon-sync"}}{{end}}
+ {{svg (Iif .Checked "octicon-trash" "octicon-sync")}}
{{end}}
{{svg (printf "octicon-%s" .Review.Type.Icon) 16 (printf "text %s" (.Review.HTMLTypeColorName))}}
diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl
index 58d3759a9d933..1243681f3a219 100644
--- a/templates/repo/issue/view_title.tmpl
+++ b/templates/repo/issue/view_title.tmpl
@@ -36,7 +36,7 @@
{{if .HasMerged}}
{{svg "octicon-git-merge" 16 "tw-mr-1"}} {{if eq .Issue.PullRequest.Status 3}}{{ctx.Locale.Tr "repo.pulls.manually_merged"}}{{else}}{{ctx.Locale.Tr "repo.pulls.merged"}}{{end}}
{{else if .Issue.IsClosed}}
- {{if .Issue.IsPull}}{{svg "octicon-git-pull-request"}}{{else}}{{svg "octicon-issue-closed"}}{{end}} {{ctx.Locale.Tr "repo.issues.closed_title"}}
+ {{svg (Iif .Issue.IsPull "octicon-git-pull-request" "octicon-issue-closed")}} {{ctx.Locale.Tr "repo.issues.closed_title"}}
{{else if .Issue.IsPull}}
{{if .IsPullWorkInProgress}}
{{svg "octicon-git-pull-request-draft"}} {{ctx.Locale.Tr "repo.issues.draft_title"}}
diff --git a/templates/repo/settings/lfs_pointers.tmpl b/templates/repo/settings/lfs_pointers.tmpl
index 758aec6bb031a..4cfc0fc6730a0 100644
--- a/templates/repo/settings/lfs_pointers.tmpl
+++ b/templates/repo/settings/lfs_pointers.tmpl
@@ -41,9 +41,9 @@
{{ShortSha .Oid}}
- {{if .InRepo}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} |
- {{if .Exists}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} |
- {{if .Accessible}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}} |
+ {{svg (Iif .InRepo "octicon-check" "octicon-x")}} |
+ {{svg (Iif .Exists "octicon-check" "octicon-x")}} |
+ {{svg (Iif .Accessible "octicon-check" "octicon-x")}} |
{{ctx.Locale.Tr "repo.settings.lfs_findcommits"}}
|
diff --git a/templates/repo/star_unstar.tmpl b/templates/repo/star_unstar.tmpl
index 0f09d8b4925a6..9234a0d19616c 100644
--- a/templates/repo/star_unstar.tmpl
+++ b/templates/repo/star_unstar.tmpl
@@ -3,7 +3,7 @@
{{$buttonText := ctx.Locale.Tr "repo.star"}}
{{if $.IsStaringRepo}}{{$buttonText = ctx.Locale.Tr "repo.unstar"}}{{end}}
diff --git a/tests/integration/api_repo_lfs_locks_test.go b/tests/integration/api_repo_lfs_locks_test.go
index 5aa1396941ddd..427e0b9fb11db 100644
--- a/tests/integration/api_repo_lfs_locks_test.go
+++ b/tests/integration/api_repo_lfs_locks_test.go
@@ -105,7 +105,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
for _, test := range tests {
session := loginUser(t, test.user.Name)
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/%s.git/info/lfs/locks", test.repo.FullName()), map[string]string{"path": test.path})
- req.Header.Set("Accept", lfs.MediaType)
+ req.Header.Set("Accept", lfs.AcceptHeader)
req.Header.Set("Content-Type", lfs.MediaType)
resp := session.MakeRequest(t, req, test.httpResult)
if len(test.addTime) > 0 {
@@ -123,7 +123,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
for _, test := range resultsTests {
session := loginUser(t, test.user.Name)
req := NewRequestf(t, "GET", "/%s.git/info/lfs/locks", test.repo.FullName())
- req.Header.Set("Accept", lfs.MediaType)
+ req.Header.Set("Accept", lfs.AcceptHeader)
resp := session.MakeRequest(t, req, http.StatusOK)
var lfsLocks api.LFSLockList
DecodeJSON(t, resp, &lfsLocks)
@@ -135,7 +135,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
}
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/%s.git/info/lfs/locks/verify", test.repo.FullName()), map[string]string{})
- req.Header.Set("Accept", lfs.MediaType)
+ req.Header.Set("Accept", lfs.AcceptHeader)
req.Header.Set("Content-Type", lfs.MediaType)
resp = session.MakeRequest(t, req, http.StatusOK)
var lfsLocksVerify api.LFSLockListVerify
@@ -159,7 +159,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
for _, test := range deleteTests {
session := loginUser(t, test.user.Name)
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/%s.git/info/lfs/locks/%s/unlock", test.repo.FullName(), test.lockID), map[string]string{})
- req.Header.Set("Accept", lfs.MediaType)
+ req.Header.Set("Accept", lfs.AcceptHeader)
req.Header.Set("Content-Type", lfs.MediaType)
resp := session.MakeRequest(t, req, http.StatusOK)
var lfsLockRep api.LFSLockResponse
@@ -172,7 +172,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
for _, test := range resultsTests {
session := loginUser(t, test.user.Name)
req := NewRequestf(t, "GET", "/%s.git/info/lfs/locks", test.repo.FullName())
- req.Header.Set("Accept", lfs.MediaType)
+ req.Header.Set("Accept", lfs.AcceptHeader)
resp := session.MakeRequest(t, req, http.StatusOK)
var lfsLocks api.LFSLockList
DecodeJSON(t, resp, &lfsLocks)
diff --git a/tests/integration/api_repo_lfs_test.go b/tests/integration/api_repo_lfs_test.go
index 211dcf76c1128..6b42b83bc5a1e 100644
--- a/tests/integration/api_repo_lfs_test.go
+++ b/tests/integration/api_repo_lfs_test.go
@@ -84,7 +84,7 @@ func TestAPILFSBatch(t *testing.T) {
newRequest := func(t testing.TB, br *lfs.BatchRequest) *RequestWrapper {
return NewRequestWithJSON(t, "POST", "/user2/lfs-batch-repo.git/info/lfs/objects/batch", br).
- SetHeader("Accept", lfs.MediaType).
+ SetHeader("Accept", lfs.AcceptHeader).
SetHeader("Content-Type", lfs.MediaType)
}
decodeResponse := func(t *testing.T, b *bytes.Buffer) *lfs.BatchResponse {
@@ -447,7 +447,7 @@ func TestAPILFSVerify(t *testing.T) {
newRequest := func(t testing.TB, p *lfs.Pointer) *RequestWrapper {
return NewRequestWithJSON(t, "POST", "/user2/lfs-verify-repo.git/info/lfs/verify", p).
- SetHeader("Accept", lfs.MediaType).
+ SetHeader("Accept", lfs.AcceptHeader).
SetHeader("Content-Type", lfs.MediaType)
}