diff --git a/models/issue_assignees.go b/models/issue_assignees.go index 577ed860f..05e1797c1 100644 --- a/models/issue_assignees.go +++ b/models/issue_assignees.go @@ -81,23 +81,6 @@ func isUserAssignedToIssue(e Engine, issue *Issue, user *User) (isAssigned bool, return e.Get(&IssueAssignees{IssueID: issue.ID, AssigneeID: user.ID}) } -// MakeAssigneeList concats a string with all names of the assignees. Useful for logs. -func MakeAssigneeList(issue *Issue) (assigneeList string, err error) { - err = issue.loadAssignees(x) - if err != nil { - return "", err - } - - for in, assignee := range issue.Assignees { - assigneeList += assignee.Name - - if len(issue.Assignees) > (in + 1) { - assigneeList += ", " - } - } - return -} - // ClearAssigneeByUserID deletes all assignments of an user func clearAssigneeByUserID(sess *xorm.Session, userID int64) (err error) { _, err = sess.Delete(&IssueAssignees{AssigneeID: userID}) diff --git a/models/update.go b/models/update.go index 8e18450db..421c44bb4 100644 --- a/models/update.go +++ b/models/update.go @@ -9,20 +9,6 @@ import ( "strings" ) -// PushUpdateDeleteTags updates a number of delete tags -func PushUpdateDeleteTags(repo *Repository, tags []string) error { - sess := x.NewSession() - defer sess.Close() - if err := sess.Begin(); err != nil { - return fmt.Errorf("Unable to begin sess in PushUpdateDeleteTags: %v", err) - } - if err := pushUpdateDeleteTags(sess, repo, tags); err != nil { - return err - } - - return sess.Commit() -} - // PushUpdateDeleteTagsContext updates a number of delete tags with context func PushUpdateDeleteTagsContext(ctx DBContext, repo *Repository, tags []string) error { return pushUpdateDeleteTags(ctx.e, repo, tags) diff --git a/models/user.go b/models/user.go index 30ede2373..f91ffa716 100644 --- a/models/user.go +++ b/models/user.go @@ -1315,21 +1315,6 @@ func UserPath(userName string) string { return filepath.Join(setting.RepoRootPath, strings.ToLower(userName)) } -// GetUserByKeyID get user information by user's public key id -func GetUserByKeyID(keyID int64) (*User, error) { - var user User - has, err := x.Join("INNER", "public_key", "`public_key`.owner_id = `user`.id"). - Where("`public_key`.id=?", keyID). - Get(&user) - if err != nil { - return nil, err - } - if !has { - return nil, ErrUserNotExist{0, "", keyID} - } - return &user, nil -} - func getUserByID(e Engine, id int64) (*User, error) { u := new(User) has, err := e.ID(id).Get(u) diff --git a/modules/base/tool.go b/modules/base/tool.go index cb9b99614..86606c8be 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -6,13 +6,11 @@ package base import ( "crypto/md5" - "crypto/rand" "crypto/sha1" "crypto/sha256" "encoding/base64" "encoding/hex" "fmt" - "io" "net/http" "net/url" "os" @@ -75,18 +73,6 @@ func BasicAuthEncode(username, password string) string { return base64.StdEncoding.EncodeToString([]byte(username + ":" + password)) } -// GetRandomBytesAsBase64 generates a random base64 string from n bytes -func GetRandomBytesAsBase64(n int) string { - bytes := make([]byte, 32) - _, err := io.ReadFull(rand.Reader, bytes) - - if err != nil { - log.Fatal("Error reading random bytes: %v", err) - } - - return base64.RawURLEncoding.EncodeToString(bytes) -} - // VerifyTimeLimitCode verify time limit code func VerifyTimeLimitCode(data string, minutes int, code string) bool { if len(code) <= 18 { diff --git a/modules/structs/user_app.go b/modules/structs/user_app.go index a0b0c3cb7..44df5a6a4 100644 --- a/modules/structs/user_app.go +++ b/modules/structs/user_app.go @@ -6,15 +6,9 @@ package structs import ( - "encoding/base64" "time" ) -// BasicAuthEncode generate base64 of basic auth head -func BasicAuthEncode(user, pass string) string { - return base64.StdEncoding.EncodeToString([]byte(user + ":" + pass)) -} - // AccessToken represents an API access token. // swagger:response AccessToken type AccessToken struct { diff --git a/modules/structs/utils.go b/modules/structs/utils.go deleted file mode 100644 index aaeb653d0..000000000 --- a/modules/structs/utils.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package structs - -// Bool return address of bool value -func Bool(v bool) *bool { - return &v -} - -// String return address of string value -func String(v string) *string { - return &v -} - -// Int64 return address of int64 value -func Int64(v int64) *int64 { - return &v -} diff --git a/modules/templates/helper.go b/modules/templates/helper.go index a97431a69..9d3206934 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -437,31 +437,6 @@ func Sha1(str string) string { return base.EncodeSha1(str) } -// ReplaceLeft replaces all prefixes 'oldS' in 's' with 'newS'. -func ReplaceLeft(s, oldS, newS string) string { - oldLen, newLen, i, n := len(oldS), len(newS), 0, 0 - for ; i < len(s) && strings.HasPrefix(s[i:], oldS); n++ { - i += oldLen - } - - // simple optimization - if n == 0 { - return s - } - - // allocating space for the new string - curLen := n*newLen + len(s[i:]) - replacement := make([]byte, curLen) - - j := 0 - for ; j < n*newLen; j += newLen { - copy(replacement[j:j+newLen], newS) - } - - copy(replacement[j:], s[i:]) - return string(replacement) -} - // RenderCommitMessage renders commit message with XSS-safe and special links. func RenderCommitMessage(msg, urlPrefix string, metas map[string]string) template.HTML { return RenderCommitMessageLink(msg, urlPrefix, "", metas) diff --git a/routers/api/v1/utils/utils.go b/routers/api/v1/utils/utils.go index e02406d13..092ea3dbb 100644 --- a/routers/api/v1/utils/utils.go +++ b/routers/api/v1/utils/utils.go @@ -13,14 +13,6 @@ import ( "code.gitea.io/gitea/modules/convert" ) -// UserID user ID of authenticated user, or 0 if not authenticated -func UserID(ctx *context.APIContext) int64 { - if ctx.User == nil { - return 0 - } - return ctx.User.ID -} - // GetQueryBeforeSince return parsed time (unix format) from URL query's before and since func GetQueryBeforeSince(ctx *context.APIContext) (before, since int64, err error) { qCreatedBefore := strings.Trim(ctx.Query("before"), " ") diff --git a/routers/private/internal.go b/routers/private/internal.go index b68a96c64..5bc01b0ae 100644 --- a/routers/private/internal.go +++ b/routers/private/internal.go @@ -8,7 +8,6 @@ package private import ( "strings" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/private" "code.gitea.io/gitea/modules/setting" @@ -27,55 +26,6 @@ func CheckInternalToken(ctx *macaron.Context) { } } -//GetRepositoryByOwnerAndName chainload to models.GetRepositoryByOwnerAndName -func GetRepositoryByOwnerAndName(ctx *macaron.Context) { - //TODO use repo.Get(ctx *context.APIContext) ? - ownerName := ctx.Params(":owner") - repoName := ctx.Params(":repo") - repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName) - if err != nil { - ctx.JSON(500, map[string]interface{}{ - "err": err.Error(), - }) - return - } - ctx.JSON(200, repo) -} - -//CheckUnitUser chainload to models.CheckUnitUser -func CheckUnitUser(ctx *macaron.Context) { - repoID := ctx.ParamsInt64(":repoid") - userID := ctx.ParamsInt64(":userid") - repo, err := models.GetRepositoryByID(repoID) - if err != nil { - ctx.JSON(500, map[string]interface{}{ - "err": err.Error(), - }) - return - } - - var user *models.User - if userID > 0 { - user, err = models.GetUserByID(userID) - if err != nil { - ctx.JSON(500, map[string]interface{}{ - "err": err.Error(), - }) - return - } - } - - perm, err := models.GetUserRepoPermission(repo, user) - if err != nil { - ctx.JSON(500, map[string]interface{}{ - "err": err.Error(), - }) - return - } - - ctx.JSON(200, perm.UnitAccessMode(models.UnitType(ctx.QueryInt("unitType")))) -} - // RegisterRoutes registers all internal APIs routes to web application. // These APIs will be invoked by internal commands for example `gitea serv` and etc. func RegisterRoutes(m *macaron.Macaron) { diff --git a/services/pull/patch.go b/services/pull/patch.go index 815263e89..96145fcd9 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -19,16 +19,6 @@ import ( "code.gitea.io/gitea/modules/log" ) -// DownloadDiff will write the patch for the pr to the writer -func DownloadDiff(pr *models.PullRequest, w io.Writer, patch bool) error { - return DownloadDiffOrPatch(pr, w, false) -} - -// DownloadPatch will write the patch for the pr to the writer -func DownloadPatch(pr *models.PullRequest, w io.Writer, patch bool) error { - return DownloadDiffOrPatch(pr, w, true) -} - // DownloadDiffOrPatch will write the patch for the pr to the writer func DownloadDiffOrPatch(pr *models.PullRequest, w io.Writer, patch bool) error { // Clone base repo.