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
|
||||
|
||||
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
|
||||
// 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(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
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
|
|
@ -48,8 +48,10 @@ func (db *Commitstore) GetCommitList(repo *model.Repo) ([]*model.Commit, error)
|
|||
|
||||
// GetCommitListUser retrieves a list of latest commits
|
||||
// from the datastore accessible to the specified user.
|
||||
func (db *Commitstore) GetCommitListUser(user *model.User) ([]*model.Commit, error) {
|
||||
return nil, nil
|
||||
func (db *Commitstore) GetCommitListUser(user *model.User) ([]*model.CommitRepo, error) {
|
||||
var commits []*model.CommitRepo
|
||||
var err = meddler.QueryAll(db, &commits, rebind(commitListUserQuery), user.ID)
|
||||
return commits, err
|
||||
}
|
||||
|
||||
// PostCommit saves a commit in the datastore.
|
||||
|
@ -84,6 +86,28 @@ DELETE FROM commits
|
|||
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.
|
||||
const commitListQuery = `
|
||||
SELECT *
|
||||
|
|
|
@ -10,7 +10,8 @@ import (
|
|||
func TestCommitstore(t *testing.T) {
|
||||
db := mustConnectTest()
|
||||
cs := NewCommitstore(db)
|
||||
//ps := NewPermstore(db)
|
||||
rs := NewRepostore(db)
|
||||
ps := NewPermstore(db)
|
||||
defer db.Close()
|
||||
|
||||
g := goblin.Goblin(t)
|
||||
|
@ -20,6 +21,7 @@ func TestCommitstore(t *testing.T) {
|
|||
// table data from the database.
|
||||
g.BeforeEach(func() {
|
||||
db.Exec("DELETE FROM perms")
|
||||
db.Exec("DELETE FROM repos")
|
||||
db.Exec("DELETE FROM commits")
|
||||
})
|
||||
|
||||
|
@ -166,47 +168,67 @@ func TestCommitstore(t *testing.T) {
|
|||
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() {
|
||||
perm1 := model.Perm{
|
||||
RepoID: 1,
|
||||
UserID: 1,
|
||||
Read: true,
|
||||
Write: true,
|
||||
Admin: true,
|
||||
}
|
||||
commit1 := model.Commit{
|
||||
RepoID: 1,
|
||||
Branch: "foo",
|
||||
Sha: "85f8c029b902ed9400bc600bac301a0aadb144ac",
|
||||
Status: model.StatusFailure,
|
||||
}
|
||||
commit2 := model.Commit{
|
||||
RepoID: 1,
|
||||
Branch: "foo",
|
||||
Sha: "0a74b46d7d62b737b6906897f48dbeb72cfda222",
|
||||
Status: model.StatusSuccess,
|
||||
}
|
||||
commit3 := model.Commit{
|
||||
RepoID: 2,
|
||||
Branch: "baz",
|
||||
Sha: "0a74b46d7d62b737b6906897f48dbeb72cfda222",
|
||||
Status: model.StatusSuccess,
|
||||
}
|
||||
cs.PutCommit(&commit1)
|
||||
cs.PutCommit(&commit2)
|
||||
cs.PutCommit(&commit3)
|
||||
ps.PutPerm(&perm1)
|
||||
commits, err := cs.GetCommitListUser(&model.User{ID: 1})
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(len(commits)).Equal(2)
|
||||
g.Assert(commits[0].ID).Equal(commit2.ID)
|
||||
g.Assert(commits[0].RepoID).Equal(commit2.RepoID)
|
||||
g.Assert(commits[0].Branch).Equal(commit2.Branch)
|
||||
g.Assert(commits[0].Sha).Equal(commit2.Sha)
|
||||
})
|
||||
*/
|
||||
g.It("Should get the recent Commit List for a User", func() {
|
||||
repo1 := model.Repo{
|
||||
UserID: 1,
|
||||
Remote: "enterprise.github.com",
|
||||
Host: "github.drone.io",
|
||||
Owner: "bradrydzewski",
|
||||
Name: "drone",
|
||||
}
|
||||
repo2 := model.Repo{
|
||||
UserID: 1,
|
||||
Remote: "enterprise.github.com",
|
||||
Host: "github.drone.io",
|
||||
Owner: "drone",
|
||||
Name: "drone",
|
||||
}
|
||||
rs.PostRepo(&repo1)
|
||||
rs.PostRepo(&repo2)
|
||||
commit1 := model.Commit{
|
||||
RepoID: repo1.ID,
|
||||
Branch: "foo",
|
||||
Sha: "85f8c029b902ed9400bc600bac301a0aadb144ac",
|
||||
Status: model.StatusFailure,
|
||||
}
|
||||
commit2 := model.Commit{
|
||||
RepoID: repo2.ID,
|
||||
Branch: "bar",
|
||||
Sha: "0a74b46d7d62b737b6906897f48dbeb72cfda222",
|
||||
Status: model.StatusSuccess,
|
||||
}
|
||||
commit3 := model.Commit{
|
||||
RepoID: 99999,
|
||||
Branch: "baz",
|
||||
Sha: "0a74b46d7d62b737b6906897f48dbeb72cfda222",
|
||||
Status: model.StatusSuccess,
|
||||
}
|
||||
cs.PostCommit(&commit1)
|
||||
cs.PostCommit(&commit2)
|
||||
cs.PostCommit(&commit3)
|
||||
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() {
|
||||
commit1 := model.Commit{
|
||||
|
|
Loading…
Reference in a new issue