appview,lexicons: add SHA field to sh.tangled.repo.pull #274

merged
opened by oppi.li targeting master from push-vquoltwpkuny

refers to the tip of the branch that this PR was opened from. this addition permits us to associate a CI run with a branch or fork based pull request.

Signed-off-by: oppiliappan me@oppi.li

Changed files
+78 -20
api
appview
lexicons
pulls
+36 -2
api/tangled/cbor_gen.go
···
cw := cbg.NewCborWriter(w)
-
fieldCount := 2
+
fieldCount := 3
if t.Repo == nil {
fieldCount--
···
return err
+
// t.Sha (string) (string)
+
if len("sha") > 1000000 {
+
return xerrors.Errorf("Value in field \"sha\" was too long")
+
}
+
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("sha"))); err != nil {
+
return err
+
}
+
if _, err := cw.WriteString(string("sha")); err != nil {
+
return err
+
}
+
+
if len(t.Sha) > 1000000 {
+
return xerrors.Errorf("Value in field t.Sha was too long")
+
}
+
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Sha))); err != nil {
+
return err
+
}
+
if _, err := cw.WriteString(string(t.Sha)); err != nil {
+
return err
+
}
+
// t.Repo (string) (string)
if t.Repo != nil {
···
switch string(nameBuf[:nameLen]) {
-
// t.Repo (string) (string)
+
// t.Sha (string) (string)
+
case "sha":
+
+
{
+
sval, err := cbg.ReadStringWithMax(cr, 1000000)
+
if err != nil {
+
return err
+
}
+
+
t.Sha = string(sval)
+
}
+
// t.Repo (string) (string)
case "repo":
+1
api/tangled/repopull.go
···
type RepoPull_Source struct {
Branch string `json:"branch" cborgen:"branch"`
Repo *string `json:"repo,omitempty" cborgen:"repo,omitempty"`
+
Sha string `json:"sha" cborgen:"sha"`
}
+1 -1
appview/db/artifact.go
···
}
func (a *Artifact) ArtifactAt() syntax.ATURI {
-
return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", a.Did, tangled.RepoPullNSID, a.Rkey))
+
return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", a.Did, tangled.RepoArtifactNSID, a.Rkey))
}
func AddArtifact(e Execer, artifact Artifact) error {
+6
appview/db/pulls.go
···
if p.PullSource != nil {
s := p.PullSource.AsRecord()
source = &s
+
source.Sha = p.LatestSha()
}
record := tangled.RepoPull{
···
return latestSubmission.Patch
}
+
func (p *Pull) LatestSha() string {
+
latestSubmission := p.Submissions[p.LastRoundNumber()]
+
return latestSubmission.SourceRev
+
}
+
func (p *Pull) PullAt() syntax.ATURI {
return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", p.OwnerDid, tangled.RepoPullNSID, p.Rkey))
}
+21 -11
appview/pulls/pulls.go
···
sourceBranch string,
isStacked bool,
) {
-
pullSource := &db.PullSource{
-
Branch: sourceBranch,
-
}
-
recordPullSource := &tangled.RepoPull_Source{
-
Branch: sourceBranch,
-
}
-
// Generate a patch using /compare
ksClient, err := knotclient.NewUnsignedClient(f.Knot, s.config.Core.Dev)
if err != nil {
···
return
}
+
pullSource := &db.PullSource{
+
Branch: sourceBranch,
+
}
+
recordPullSource := &tangled.RepoPull_Source{
+
Branch: sourceBranch,
+
Sha: comparison.Rev2,
+
}
+
s.createPullRequest(w, r, f, user, title, body, targetBranch, patch, sourceRev, pullSource, recordPullSource, isStacked)
}
···
return
}
-
s.createPullRequest(w, r, f, user, title, body, targetBranch, patch, sourceRev, &db.PullSource{
+
pullSource := &db.PullSource{
Branch: sourceBranch,
RepoAt: &forkAtUri,
-
}, &tangled.RepoPull_Source{Branch: sourceBranch, Repo: &fork.AtUri}, isStacked)
+
}
+
recordPullSource := &tangled.RepoPull_Source{
+
Branch: sourceBranch,
+
Repo: &fork.AtUri,
+
Sha: sourceRev,
+
}
+
+
s.createPullRequest(w, r, f, user, title, body, targetBranch, patch, sourceRev, pullSource, recordPullSource, isStacked)
}
func (s *Pulls) createPullRequest(
···
) {
if isStacked {
// creates a series of PRs, each linking to the previous, identified by jj's change-id
-
s.createStackedPulLRequest(
+
s.createStackedPullRequest(
w,
r,
f,
···
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pullId))
-
func (s *Pulls) createStackedPulLRequest(
+
func (s *Pulls) createStackedPullRequest(
w http.ResponseWriter,
r *http.Request,
f *reporesolver.ResolvedRepo,
···
if pull.IsBranchBased() {
recordPullSource = &tangled.RepoPull_Source{
Branch: pull.PullSource.Branch,
+
Sha: sourceRev,
if pull.IsForkBased() {
···
recordPullSource = &tangled.RepoPull_Source{
Branch: pull.PullSource.Branch,
Repo: &repoAt,
+
Sha: sourceRev,
+1 -1
appview/repo/index.go
···
for _, c := range commitsTrunc {
shas = append(shas, c.Hash.String())
}
-
pipelines, err := rp.getPipelineStatuses(repoInfo, shas)
+
pipelines, err := getPipelineStatuses(rp.db, repoInfo, shas)
if err != nil {
log.Printf("failed to fetch pipeline statuses: %s", err)
// non-fatal
+2 -2
appview/repo/repo.go
···
for _, c := range repolog.Commits {
shas = append(shas, c.Hash.String())
}
-
pipelines, err := rp.getPipelineStatuses(repoInfo, shas)
+
pipelines, err := getPipelineStatuses(rp.db, repoInfo, shas)
if err != nil {
log.Println(err)
// non-fatal
···
user := rp.oauth.GetUser(r)
repoInfo := f.RepoInfo(user)
-
pipelines, err := rp.getPipelineStatuses(repoInfo, []string{result.Diff.Commit.This})
+
pipelines, err := getPipelineStatuses(rp.db, repoInfo, []string{result.Diff.Commit.This})
if err != nil {
log.Println(err)
// non-fatal
+3 -2
appview/repo/repo_util.go
···
// grab pipelines from DB and munge that into a hashmap with commit sha as key
//
// golang is so blessed that it requires 35 lines of imperative code for this
-
func (rp *Repo) getPipelineStatuses(
+
func getPipelineStatuses(
+
d *db.DB,
repoInfo repoinfo.RepoInfo,
shas []string,
) (map[string]db.Pipeline, error) {
···
}
ps, err := db.GetPipelineStatuses(
-
rp.db,
+
d,
db.FilterEq("repo_owner", repoInfo.OwnerDid),
db.FilterEq("repo_name", repoInfo.Name),
db.FilterEq("knot", repoInfo.Knot),
+7 -1
lexicons/pulls/pull.json
···
"source": {
"type": "object",
"required": [
-
"branch"
+
"branch",
+
"sha"
],
"properties": {
"branch": {
"type": "string"
},
+
"sha": {
+
"type": "string",
+
"minLength": 40,
+
"maxLength": 40
+
},
"repo": {
"type": "string",
"format": "at-uri"