Skip to content

Commit 5813244

Browse files
GustedEarl Warren
authored andcommitted
chore: Remove ChangeMilestoneStatus (go-gitea#6741)
- Introduced in 5ed5aa5 and removed in 4027c5d. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6741 Reviewed-by: Earl Warren <[email protected]> Co-authored-by: Gusted <[email protected]> Co-committed-by: Gusted <[email protected]>
1 parent 7678386 commit 5813244

File tree

9 files changed

+9
-83
lines changed

9 files changed

+9
-83
lines changed

.deadcode-out

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ code.gitea.io/gitea/models/actions
2222
ScheduleList.LoadTriggerUser
2323
ScheduleList.LoadRepos
2424

25-
code.gitea.io/gitea/models/asymkey
26-
ErrGPGKeyAccessDenied.Error
27-
ErrGPGKeyAccessDenied.Unwrap
28-
HasDeployKey
29-
3025
code.gitea.io/gitea/models/auth
3126
GetSourceByName
3227
WebAuthnCredentials
@@ -54,9 +49,7 @@ code.gitea.io/gitea/models/git
5449

5550
code.gitea.io/gitea/models/issues
5651
IsErrUnknownDependencyType
57-
ErrNewIssueInsert.Error
5852
IsErrIssueWasClosed
59-
ChangeMilestoneStatus
6053

6154
code.gitea.io/gitea/models/organization
6255
GetTeamNamesByID

models/asymkey/error.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -192,28 +192,6 @@ func (err ErrGPGKeyIDAlreadyUsed) Unwrap() error {
192192
return util.ErrAlreadyExist
193193
}
194194

195-
// ErrGPGKeyAccessDenied represents a "GPGKeyAccessDenied" kind of Error.
196-
type ErrGPGKeyAccessDenied struct {
197-
UserID int64
198-
KeyID int64
199-
}
200-
201-
// IsErrGPGKeyAccessDenied checks if an error is a ErrGPGKeyAccessDenied.
202-
func IsErrGPGKeyAccessDenied(err error) bool {
203-
_, ok := err.(ErrGPGKeyAccessDenied)
204-
return ok
205-
}
206-
207-
// Error pretty-prints an error of type ErrGPGKeyAccessDenied.
208-
func (err ErrGPGKeyAccessDenied) Error() string {
209-
return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d]",
210-
err.UserID, err.KeyID)
211-
}
212-
213-
func (err ErrGPGKeyAccessDenied) Unwrap() error {
214-
return util.ErrPermissionDenied
215-
}
216-
217195
// ErrKeyAccessDenied represents a "KeyAccessDenied" kind of error.
218196
type ErrKeyAccessDenied struct {
219197
UserID int64

models/asymkey/ssh_key_deploy.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,6 @@ func addDeployKey(ctx context.Context, keyID, repoID int64, name, fingerprint st
105105
return key, db.Insert(ctx, key)
106106
}
107107

108-
// HasDeployKey returns true if public key is a deploy key of given repository.
109-
func HasDeployKey(ctx context.Context, keyID, repoID int64) bool {
110-
has, _ := db.GetEngine(ctx).
111-
Where("key_id = ? AND repo_id = ?", keyID, repoID).
112-
Get(new(DeployKey))
113-
return has
114-
}
115-
116108
// AddDeployKey add new deploy key to database and authorized_keys file.
117109
func AddDeployKey(ctx context.Context, repoID int64, name, content string, readOnly bool) (*DeployKey, error) {
118110
fingerprint, err := CalcFingerprint(content)

models/issues/issue.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,6 @@ func (err ErrIssueIsClosed) Error() string {
6363
return fmt.Sprintf("issue is closed [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
6464
}
6565

66-
// ErrNewIssueInsert is used when the INSERT statement in newIssue fails
67-
type ErrNewIssueInsert struct {
68-
OriginalError error
69-
}
70-
71-
// IsErrNewIssueInsert checks if an error is a ErrNewIssueInsert.
72-
func IsErrNewIssueInsert(err error) bool {
73-
_, ok := err.(ErrNewIssueInsert)
74-
return ok
75-
}
76-
77-
func (err ErrNewIssueInsert) Error() string {
78-
return err.OriginalError.Error()
79-
}
80-
8166
// ErrIssueWasClosed is used when close a closed issue
8267
type ErrIssueWasClosed struct {
8368
ID int64

models/issues/issue_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, la
433433
LabelIDs: labelIDs,
434434
Attachments: uuids,
435435
}); err != nil {
436-
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) || IsErrNewIssueInsert(err) {
436+
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
437437
return err
438438
}
439439
return fmt.Errorf("newIssue: %w", err)

models/issues/milestone.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -251,21 +251,6 @@ func ChangeMilestoneStatusByRepoIDAndID(ctx context.Context, repoID, milestoneID
251251
return committer.Commit()
252252
}
253253

254-
// ChangeMilestoneStatus changes the milestone open/closed status.
255-
func ChangeMilestoneStatus(ctx context.Context, m *Milestone, isClosed bool) (err error) {
256-
ctx, committer, err := db.TxContext(ctx)
257-
if err != nil {
258-
return err
259-
}
260-
defer committer.Close()
261-
262-
if err := changeMilestoneStatus(ctx, m, isClosed); err != nil {
263-
return err
264-
}
265-
266-
return committer.Commit()
267-
}
268-
269254
func changeMilestoneStatus(ctx context.Context, m *Milestone, isClosed bool) error {
270255
m.IsClosed = isClosed
271256
if isClosed {

models/issues/milestone_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,17 +298,16 @@ func TestNewMilestone(t *testing.T) {
298298
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &issues_model.Milestone{})
299299
}
300300

301-
func TestChangeMilestoneStatus(t *testing.T) {
301+
func TestChangeMilestoneStatusByRepoIDAndID(t *testing.T) {
302302
require.NoError(t, unittest.PrepareTestDatabase())
303-
milestone := unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1})
304303

305-
require.NoError(t, issues_model.ChangeMilestoneStatus(db.DefaultContext, milestone, true))
306-
unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}, "is_closed=1")
307-
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &issues_model.Milestone{})
304+
require.NoError(t, issues_model.ChangeMilestoneStatusByRepoIDAndID(db.DefaultContext, 1, 1, true))
305+
unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1, IsClosed: true})
306+
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: 1}, &issues_model.Milestone{})
308307

309-
require.NoError(t, issues_model.ChangeMilestoneStatus(db.DefaultContext, milestone, false))
308+
require.NoError(t, issues_model.ChangeMilestoneStatusByRepoIDAndID(db.DefaultContext, 1, 1, false))
310309
unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}, "is_closed=0")
311-
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &issues_model.Milestone{})
310+
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: 1}, &issues_model.Milestone{})
312311
}
313312

314313
func TestDeleteMilestoneByRepoID(t *testing.T) {

models/issues/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *Iss
575575
Attachments: uuids,
576576
IsPull: true,
577577
}); err != nil {
578-
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) || IsErrNewIssueInsert(err) {
578+
if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
579579
return err
580580
}
581581
return fmt.Errorf("newIssue: %w", err)

routers/api/v1/user/gpg_key.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,7 @@ func DeleteGPGKey(ctx *context.APIContext) {
303303
}
304304

305305
if err := asymkey_model.DeleteGPGKey(ctx, ctx.Doer, ctx.ParamsInt64(":id")); err != nil {
306-
if asymkey_model.IsErrGPGKeyAccessDenied(err) {
307-
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
308-
} else {
309-
ctx.Error(http.StatusInternalServerError, "DeleteGPGKey", err)
310-
}
306+
ctx.Error(http.StatusInternalServerError, "DeleteGPGKey", err)
311307
return
312308
}
313309

@@ -317,8 +313,6 @@ func DeleteGPGKey(ctx *context.APIContext) {
317313
// HandleAddGPGKeyError handle add GPGKey error
318314
func HandleAddGPGKeyError(ctx *context.APIContext, err error, token string) {
319315
switch {
320-
case asymkey_model.IsErrGPGKeyAccessDenied(err):
321-
ctx.Error(http.StatusUnprocessableEntity, "GPGKeyAccessDenied", "You do not have access to this GPG key")
322316
case asymkey_model.IsErrGPGKeyIDAlreadyUsed(err):
323317
ctx.Error(http.StatusUnprocessableEntity, "GPGKeyIDAlreadyUsed", "A key with the same id already exists")
324318
case asymkey_model.IsErrGPGKeyParsing(err):

0 commit comments

Comments
 (0)