hooked up commit feed for user dashboard
This commit is contained in:
parent
17e5b76ec8
commit
e725abe204
4 changed files with 93 additions and 47 deletions
|
@ -15,4 +15,4 @@ RUN make deps build embed install
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/local/bin/droned"]
|
ENTRYPOINT ["/usr/local/bin/droned"]
|
||||||
CMD ["--port=:80"]
|
CMD ["--bind=:80"]
|
||||||
|
|
|
@ -25,7 +25,7 @@ type Commitstore interface {
|
||||||
|
|
||||||
// GetCommitListUser retrieves a list of latest commits
|
// GetCommitListUser retrieves a list of latest commits
|
||||||
// from the datastore accessible to the specified user.
|
// from the datastore accessible to the specified user.
|
||||||
GetCommitListUser(user *model.User) ([]*model.Commit, error)
|
GetCommitListUser(user *model.User) ([]*model.CommitRepo, error)
|
||||||
|
|
||||||
// PostCommit saves a commit in the datastore.
|
// PostCommit saves a commit in the datastore.
|
||||||
PostCommit(commit *model.Commit) error
|
PostCommit(commit *model.Commit) error
|
||||||
|
@ -68,7 +68,7 @@ func GetCommitList(c context.Context, repo *model.Repo) ([]*model.Commit, error)
|
||||||
|
|
||||||
// GetCommitListUser retrieves a list of latest commits
|
// GetCommitListUser retrieves a list of latest commits
|
||||||
// from the datastore accessible to the specified user.
|
// from the datastore accessible to the specified user.
|
||||||
func GetCommitListUser(c context.Context, user *model.User) ([]*model.Commit, error) {
|
func GetCommitListUser(c context.Context, user *model.User) ([]*model.CommitRepo, error) {
|
||||||
return FromContext(c).GetCommitListUser(user)
|
return FromContext(c).GetCommitListUser(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,10 @@ func (db *Commitstore) GetCommitList(repo *model.Repo) ([]*model.Commit, error)
|
||||||
|
|
||||||
// GetCommitListUser retrieves a list of latest commits
|
// GetCommitListUser retrieves a list of latest commits
|
||||||
// from the datastore accessible to the specified user.
|
// from the datastore accessible to the specified user.
|
||||||
func (db *Commitstore) GetCommitListUser(user *model.User) ([]*model.Commit, error) {
|
func (db *Commitstore) GetCommitListUser(user *model.User) ([]*model.CommitRepo, error) {
|
||||||
return nil, nil
|
var commits []*model.CommitRepo
|
||||||
|
var err = meddler.QueryAll(db, &commits, rebind(commitListUserQuery), user.ID)
|
||||||
|
return commits, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostCommit saves a commit in the datastore.
|
// PostCommit saves a commit in the datastore.
|
||||||
|
@ -84,6 +86,28 @@ DELETE FROM commits
|
||||||
WHERE commit_id = ?
|
WHERE commit_id = ?
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// SQL query to retrieve the latest Commits accessible
|
||||||
|
// to ta specific user account
|
||||||
|
const commitListUserQuery = `
|
||||||
|
SELECT r.repo_remote, r.repo_host, r.repo_owner, r.repo_name, c.*
|
||||||
|
FROM
|
||||||
|
commits c
|
||||||
|
,repos r
|
||||||
|
WHERE c.repo_id = r.repo_id
|
||||||
|
AND c.commit_id IN (
|
||||||
|
SELECT max(c.commit_id)
|
||||||
|
FROM
|
||||||
|
commits c
|
||||||
|
,repos r
|
||||||
|
,perms p
|
||||||
|
WHERE c.repo_id = r.repo_id
|
||||||
|
AND r.repo_id = p.repo_id
|
||||||
|
AND p.user_id = ?
|
||||||
|
AND c.commit_status NOT IN ('Started', 'Pending')
|
||||||
|
GROUP BY r.repo_id
|
||||||
|
) ORDER BY c.commit_created DESC LIMIT 5;
|
||||||
|
`
|
||||||
|
|
||||||
// SQL query to retrieve the latest Commits across all branches.
|
// SQL query to retrieve the latest Commits across all branches.
|
||||||
const commitListQuery = `
|
const commitListQuery = `
|
||||||
SELECT *
|
SELECT *
|
||||||
|
|
|
@ -10,7 +10,8 @@ import (
|
||||||
func TestCommitstore(t *testing.T) {
|
func TestCommitstore(t *testing.T) {
|
||||||
db := mustConnectTest()
|
db := mustConnectTest()
|
||||||
cs := NewCommitstore(db)
|
cs := NewCommitstore(db)
|
||||||
//ps := NewPermstore(db)
|
rs := NewRepostore(db)
|
||||||
|
ps := NewPermstore(db)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
g := goblin.Goblin(t)
|
g := goblin.Goblin(t)
|
||||||
|
@ -20,6 +21,7 @@ func TestCommitstore(t *testing.T) {
|
||||||
// table data from the database.
|
// table data from the database.
|
||||||
g.BeforeEach(func() {
|
g.BeforeEach(func() {
|
||||||
db.Exec("DELETE FROM perms")
|
db.Exec("DELETE FROM perms")
|
||||||
|
db.Exec("DELETE FROM repos")
|
||||||
db.Exec("DELETE FROM commits")
|
db.Exec("DELETE FROM commits")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -166,47 +168,67 @@ func TestCommitstore(t *testing.T) {
|
||||||
g.Assert(commits[0].Sha).Equal(commit2.Sha)
|
g.Assert(commits[0].Sha).Equal(commit2.Sha)
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("Should get the recent Commit List for a User")
|
g.It("Should get the recent Commit List for a User", func() {
|
||||||
/*
|
repo1 := model.Repo{
|
||||||
g.It("Should get the recent Commit List for a User", func() {
|
UserID: 1,
|
||||||
perm1 := model.Perm{
|
Remote: "enterprise.github.com",
|
||||||
RepoID: 1,
|
Host: "github.drone.io",
|
||||||
UserID: 1,
|
Owner: "bradrydzewski",
|
||||||
Read: true,
|
Name: "drone",
|
||||||
Write: true,
|
}
|
||||||
Admin: true,
|
repo2 := model.Repo{
|
||||||
}
|
UserID: 1,
|
||||||
commit1 := model.Commit{
|
Remote: "enterprise.github.com",
|
||||||
RepoID: 1,
|
Host: "github.drone.io",
|
||||||
Branch: "foo",
|
Owner: "drone",
|
||||||
Sha: "85f8c029b902ed9400bc600bac301a0aadb144ac",
|
Name: "drone",
|
||||||
Status: model.StatusFailure,
|
}
|
||||||
}
|
rs.PostRepo(&repo1)
|
||||||
commit2 := model.Commit{
|
rs.PostRepo(&repo2)
|
||||||
RepoID: 1,
|
commit1 := model.Commit{
|
||||||
Branch: "foo",
|
RepoID: repo1.ID,
|
||||||
Sha: "0a74b46d7d62b737b6906897f48dbeb72cfda222",
|
Branch: "foo",
|
||||||
Status: model.StatusSuccess,
|
Sha: "85f8c029b902ed9400bc600bac301a0aadb144ac",
|
||||||
}
|
Status: model.StatusFailure,
|
||||||
commit3 := model.Commit{
|
}
|
||||||
RepoID: 2,
|
commit2 := model.Commit{
|
||||||
Branch: "baz",
|
RepoID: repo2.ID,
|
||||||
Sha: "0a74b46d7d62b737b6906897f48dbeb72cfda222",
|
Branch: "bar",
|
||||||
Status: model.StatusSuccess,
|
Sha: "0a74b46d7d62b737b6906897f48dbeb72cfda222",
|
||||||
}
|
Status: model.StatusSuccess,
|
||||||
cs.PutCommit(&commit1)
|
}
|
||||||
cs.PutCommit(&commit2)
|
commit3 := model.Commit{
|
||||||
cs.PutCommit(&commit3)
|
RepoID: 99999,
|
||||||
ps.PutPerm(&perm1)
|
Branch: "baz",
|
||||||
commits, err := cs.GetCommitListUser(&model.User{ID: 1})
|
Sha: "0a74b46d7d62b737b6906897f48dbeb72cfda222",
|
||||||
g.Assert(err == nil).IsTrue()
|
Status: model.StatusSuccess,
|
||||||
g.Assert(len(commits)).Equal(2)
|
}
|
||||||
g.Assert(commits[0].ID).Equal(commit2.ID)
|
cs.PostCommit(&commit1)
|
||||||
g.Assert(commits[0].RepoID).Equal(commit2.RepoID)
|
cs.PostCommit(&commit2)
|
||||||
g.Assert(commits[0].Branch).Equal(commit2.Branch)
|
cs.PostCommit(&commit3)
|
||||||
g.Assert(commits[0].Sha).Equal(commit2.Sha)
|
perm1 := model.Perm{
|
||||||
})
|
RepoID: repo1.ID,
|
||||||
*/
|
UserID: 1,
|
||||||
|
Read: true,
|
||||||
|
Write: true,
|
||||||
|
Admin: true,
|
||||||
|
}
|
||||||
|
perm2 := model.Perm{
|
||||||
|
RepoID: repo2.ID,
|
||||||
|
UserID: 1,
|
||||||
|
Read: true,
|
||||||
|
Write: true,
|
||||||
|
Admin: true,
|
||||||
|
}
|
||||||
|
ps.PostPerm(&perm1)
|
||||||
|
ps.PostPerm(&perm2)
|
||||||
|
commits, err := cs.GetCommitListUser(&model.User{ID: 1})
|
||||||
|
g.Assert(err == nil).IsTrue()
|
||||||
|
g.Assert(len(commits)).Equal(2)
|
||||||
|
g.Assert(commits[0].RepoID).Equal(commit1.RepoID)
|
||||||
|
g.Assert(commits[0].Branch).Equal(commit1.Branch)
|
||||||
|
g.Assert(commits[0].Sha).Equal(commit1.Sha)
|
||||||
|
})
|
||||||
|
|
||||||
g.It("Should enforce unique Sha + Branch", func() {
|
g.It("Should enforce unique Sha + Branch", func() {
|
||||||
commit1 := model.Commit{
|
commit1 := model.Commit{
|
||||||
|
|
Loading…
Reference in a new issue