diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-25 22:54:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-25 22:54:40 +0800 |
commit | cd1821a7e292b05e04fcc2a969b42d06ab512849 (patch) | |
tree | 084f97bfb24a37ec3028d15fdacb51e86cfcc368 /models | |
parent | e8e56da9ac321aacb3c06968997a45c2f133cd4e (diff) | |
download | gitea-cd1821a7e292b05e04fcc2a969b42d06ab512849.tar.gz gitea-cd1821a7e292b05e04fcc2a969b42d06ab512849.zip |
Move push update to post-receive and protected branch check to pre-receive (#1030)
* move all push update to git hook post-receive and protected branch check to git hook pre-receive
* add SSH_ORIGINAL_COMMAND check back
* remove all unused codes
* fix the import
Diffstat (limited to 'models')
-rw-r--r-- | models/fixtures/update_task.yml | 20 | ||||
-rw-r--r-- | models/models.go | 2 | ||||
-rw-r--r-- | models/update.go | 43 | ||||
-rw-r--r-- | models/update_test.go | 34 |
4 files changed, 9 insertions, 90 deletions
diff --git a/models/fixtures/update_task.yml b/models/fixtures/update_task.yml deleted file mode 100644 index ffcd5fd6fa..0000000000 --- a/models/fixtures/update_task.yml +++ /dev/null @@ -1,20 +0,0 @@ -- - id: 1 - uuid: uuid1 - ref_name: refName1 - old_commit_id: oldCommitId1 - new_commit_id: newCommitId1 - -- - id: 2 - uuid: uuid2 - ref_name: refName2 - old_commit_id: oldCommitId2 - new_commit_id: newCommitId2 - -- - id: 3 - uuid: uuid3 - ref_name: refName3 - old_commit_id: oldCommitId3 - new_commit_id: newCommitId3 diff --git a/models/models.go b/models/models.go index 0840b4600e..29428dba04 100644 --- a/models/models.go +++ b/models/models.go @@ -100,7 +100,6 @@ func init() { new(Release), new(LoginSource), new(Webhook), - new(UpdateTask), new(HookTask), new(Team), new(OrgUser), @@ -316,7 +315,6 @@ func GetStatistic() (stats Statistic) { stats.Counter.Label, _ = x.Count(new(Label)) stats.Counter.HookTask, _ = x.Count(new(HookTask)) stats.Counter.Team, _ = x.Count(new(Team)) - stats.Counter.UpdateTask, _ = x.Count(new(UpdateTask)) stats.Counter.Attachment, _ = x.Count(new(Attachment)) return } diff --git a/models/update.go b/models/update.go index 677a9bda31..3cb0608594 100644 --- a/models/update.go +++ b/models/update.go @@ -15,40 +15,15 @@ import ( "code.gitea.io/gitea/modules/log" ) -// UpdateTask defines an UpdateTask -type UpdateTask struct { - ID int64 `xorm:"pk autoincr"` - UUID string `xorm:"index"` - RefName string - OldCommitID string - NewCommitID string -} - -// AddUpdateTask adds an UpdateTask -func AddUpdateTask(task *UpdateTask) error { - _, err := x.Insert(task) - return err -} - -// GetUpdateTaskByUUID returns update task by given UUID. -func GetUpdateTaskByUUID(uuid string) (*UpdateTask, error) { - task := &UpdateTask{ - UUID: uuid, - } - has, err := x.Get(task) - if err != nil { - return nil, err - } else if !has { - return nil, ErrUpdateTaskNotExist{uuid} - } - return task, nil -} - -// DeleteUpdateTaskByUUID deletes an UpdateTask from the database -func DeleteUpdateTaskByUUID(uuid string) error { - _, err := x.Delete(&UpdateTask{UUID: uuid}) - return err -} +// env keys for git hooks need +const ( + EnvRepoName = "GITEA_REPO_NAME" + EnvRepoUsername = "GITEA_REPO_USER_NAME" + EnvRepoUserSalt = "GITEA_REPO_USER_SALT" + EnvRepoIsWiki = "GITEA_REPO_IS_WIKI" + EnvPusherName = "GITEA_PUSHER_NAME" + EnvPusherID = "GITEA_PUSHER_ID" +) // CommitToPushCommit transforms a git.Commit to PushCommit type. func CommitToPushCommit(commit *git.Commit) *PushCommit { diff --git a/models/update_test.go b/models/update_test.go index db9d7b94b9..ae95a9641b 100644 --- a/models/update_test.go +++ b/models/update_test.go @@ -14,40 +14,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestAddUpdateTask(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) - task := &UpdateTask{ - UUID: "uuid4", - RefName: "refName4", - OldCommitID: "oldCommitId4", - NewCommitID: "newCommitId4", - } - assert.NoError(t, AddUpdateTask(task)) - AssertExistsAndLoadBean(t, task) -} - -func TestGetUpdateTaskByUUID(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) - task, err := GetUpdateTaskByUUID("uuid1") - assert.NoError(t, err) - assert.Equal(t, "uuid1", task.UUID) - assert.Equal(t, "refName1", task.RefName) - assert.Equal(t, "oldCommitId1", task.OldCommitID) - assert.Equal(t, "newCommitId1", task.NewCommitID) - - _, err = GetUpdateTaskByUUID("invalid") - assert.Error(t, err) - assert.True(t, IsErrUpdateTaskNotExist(err)) -} - -func TestDeleteUpdateTaskByUUID(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) - assert.NoError(t, DeleteUpdateTaskByUUID("uuid1")) - AssertNotExistsBean(t, &UpdateTask{UUID: "uuid1"}) - - assert.NoError(t, DeleteUpdateTaskByUUID("invalid")) -} - func TestCommitToPushCommit(t *testing.T) { now := time.Now() sig := &git.Signature{ |