@ -15,10 +15,11 @@ import (
// CommitStatusSummary holds the latest commit Status of a single Commit
// CommitStatusSummary holds the latest commit Status of a single Commit
type CommitStatusSummary struct {
type CommitStatusSummary struct {
ID int64 ` xorm:"pk autoincr" `
ID int64 ` xorm:"pk autoincr" `
RepoID int64 ` xorm:"INDEX UNIQUE(repo_id_sha)" `
RepoID int64 ` xorm:"INDEX UNIQUE(repo_id_sha)" `
SHA string ` xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_id_sha)" `
SHA string ` xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_id_sha)" `
State api . CommitStatusState ` xorm:"VARCHAR(7) NOT NULL" `
State api . CommitStatusState ` xorm:"VARCHAR(7) NOT NULL" `
TargetURL string ` xorm:"TEXT" `
}
}
func init ( ) {
func init ( ) {
@ -44,9 +45,10 @@ func GetLatestCommitStatusForRepoAndSHAs(ctx context.Context, repoSHAs []RepoSHA
commitStatuses := make ( [ ] * CommitStatus , 0 , len ( repoSHAs ) )
commitStatuses := make ( [ ] * CommitStatus , 0 , len ( repoSHAs ) )
for _ , summary := range summaries {
for _ , summary := range summaries {
commitStatuses = append ( commitStatuses , & CommitStatus {
commitStatuses = append ( commitStatuses , & CommitStatus {
RepoID : summary . RepoID ,
RepoID : summary . RepoID ,
SHA : summary . SHA ,
SHA : summary . SHA ,
State : summary . State ,
State : summary . State ,
TargetURL : summary . TargetURL ,
} )
} )
}
}
return commitStatuses , nil
return commitStatuses , nil
@ -61,22 +63,24 @@ func UpdateCommitStatusSummary(ctx context.Context, repoID int64, sha string) er
// mysql will return 0 when update a record which state hasn't been changed which behaviour is different from other database,
// mysql will return 0 when update a record which state hasn't been changed which behaviour is different from other database,
// so we need to use insert in on duplicate
// so we need to use insert in on duplicate
if setting . Database . Type . IsMySQL ( ) {
if setting . Database . Type . IsMySQL ( ) {
_ , err := db . GetEngine ( ctx ) . Exec ( "INSERT INTO commit_status_summary (repo_id,sha,state ) VALUES (?,?,?) ON DUPLICATE KEY UPDATE state=?",
_ , err := db . GetEngine ( ctx ) . Exec ( "INSERT INTO commit_status_summary (repo_id,sha,state ,target_url ) VALUES (?, ?,?,?) ON DUPLICATE KEY UPDATE state=?",
repoID , sha , state . State , state . State)
repoID , sha , state . State , state . TargetURL, state . State)
return err
return err
}
}
if cnt , err := db . GetEngine ( ctx ) . Where ( "repo_id=? AND sha=?" , repoID , sha ) .
if cnt , err := db . GetEngine ( ctx ) . Where ( "repo_id=? AND sha=?" , repoID , sha ) .
Cols ( "state ") .
Cols ( "state , target_url ") .
Update ( & CommitStatusSummary {
Update ( & CommitStatusSummary {
State : state . State ,
State : state . State ,
TargetURL : state . TargetURL ,
} ) ; err != nil {
} ) ; err != nil {
return err
return err
} else if cnt == 0 {
} else if cnt == 0 {
_ , err = db . GetEngine ( ctx ) . Insert ( & CommitStatusSummary {
_ , err = db . GetEngine ( ctx ) . Insert ( & CommitStatusSummary {
RepoID : repoID ,
RepoID : repoID ,
SHA : sha ,
SHA : sha ,
State : state . State ,
State : state . State ,
TargetURL : state . TargetURL ,
} )
} )
return err
return err
}
}