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 -22
api
appview
lexicons
pulls
+36 -4
api/tangled/cbor_gen.go
··· 3014 3014 3015 3015 return nil 3016 3016 } 3017 - 3018 3017 func (t *Pipeline_Step_Environment_Elem) MarshalCBOR(w io.Writer) error { 3019 3018 if t == nil { 3020 3019 _, err := w.Write(cbg.CborNull) ··· 3511 3510 3512 3511 return nil 3513 3512 } 3514 - 3515 3513 func (t *Pipeline_Step) MarshalCBOR(w io.Writer) error { 3516 3514 if t == nil { 3517 3515 _, err := w.Write(cbg.CborNull) ··· 7268 7266 } 7269 7267 7270 7268 cw := cbg.NewCborWriter(w) 7271 - fieldCount := 2 7269 + fieldCount := 3 7272 7270 7273 7271 if t.Repo == nil { 7274 7272 fieldCount-- ··· 7278 7276 return err 7279 7277 } 7280 7278 7279 + // t.Sha (string) (string) 7280 + if len("sha") > 1000000 { 7281 + return xerrors.Errorf("Value in field \"sha\" was too long") 7282 + } 7283 + 7284 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("sha"))); err != nil { 7285 + return err 7286 + } 7287 + if _, err := cw.WriteString(string("sha")); err != nil { 7288 + return err 7289 + } 7290 + 7291 + if len(t.Sha) > 1000000 { 7292 + return xerrors.Errorf("Value in field t.Sha was too long") 7293 + } 7294 + 7295 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Sha))); err != nil { 7296 + return err 7297 + } 7298 + if _, err := cw.WriteString(string(t.Sha)); err != nil { 7299 + return err 7300 + } 7301 + 7281 7302 // t.Repo (string) (string) 7282 7303 if t.Repo != nil { 7283 7304 ··· 7376 7397 } 7377 7398 7378 7399 switch string(nameBuf[:nameLen]) { 7379 - // t.Repo (string) (string) 7400 + // t.Sha (string) (string) 7401 + case "sha": 7402 + 7403 + { 7404 + sval, err := cbg.ReadStringWithMax(cr, 1000000) 7405 + if err != nil { 7406 + return err 7407 + } 7408 + 7409 + t.Sha = string(sval) 7410 + } 7411 + // t.Repo (string) (string) 7380 7412 case "repo": 7381 7413 7382 7414 {
+1
api/tangled/repopull.go
··· 32 32 type RepoPull_Source struct { 33 33 Branch string `json:"branch" cborgen:"branch"` 34 34 Repo *string `json:"repo,omitempty" cborgen:"repo,omitempty"` 35 + Sha string `json:"sha" cborgen:"sha"` 35 36 }
+1 -1
appview/db/artifact.go
··· 27 27 } 28 28 29 29 func (a *Artifact) ArtifactAt() syntax.ATURI { 30 - return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", a.Did, tangled.RepoPullNSID, a.Rkey)) 30 + return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", a.Did, tangled.RepoArtifactNSID, a.Rkey)) 31 31 } 32 32 33 33 func AddArtifact(e Execer, artifact Artifact) error {
+6
appview/db/pulls.go
··· 87 87 if p.PullSource != nil { 88 88 s := p.PullSource.AsRecord() 89 89 source = &s 90 + source.Sha = p.LatestSha() 90 91 } 91 92 92 93 record := tangled.RepoPull{ ··· 164 165 return latestSubmission.Patch 165 166 } 166 167 168 + func (p *Pull) LatestSha() string { 169 + latestSubmission := p.Submissions[p.LastRoundNumber()] 170 + return latestSubmission.SourceRev 171 + } 172 + 167 173 func (p *Pull) PullAt() syntax.ATURI { 168 174 return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", p.OwnerDid, tangled.RepoPullNSID, p.Rkey)) 169 175 }
+21 -11
appview/pulls/pulls.go
··· 798 798 sourceBranch string, 799 799 isStacked bool, 800 800 ) { 801 - pullSource := &db.PullSource{ 802 - Branch: sourceBranch, 803 - } 804 - recordPullSource := &tangled.RepoPull_Source{ 805 - Branch: sourceBranch, 806 - } 807 - 808 801 // Generate a patch using /compare 809 802 ksClient, err := knotclient.NewUnsignedClient(f.Knot, s.config.Core.Dev) 810 803 if err != nil { ··· 828 821 return 829 822 } 830 823 824 + pullSource := &db.PullSource{ 825 + Branch: sourceBranch, 826 + } 827 + recordPullSource := &tangled.RepoPull_Source{ 828 + Branch: sourceBranch, 829 + Sha: comparison.Rev2, 830 + } 831 + 831 832 s.createPullRequest(w, r, f, user, title, body, targetBranch, patch, sourceRev, pullSource, recordPullSource, isStacked) 832 833 } 833 834 ··· 914 915 return 915 916 } 916 917 917 - s.createPullRequest(w, r, f, user, title, body, targetBranch, patch, sourceRev, &db.PullSource{ 918 + pullSource := &db.PullSource{ 918 919 Branch: sourceBranch, 919 920 RepoAt: &forkAtUri, 920 - }, &tangled.RepoPull_Source{Branch: sourceBranch, Repo: &fork.AtUri}, isStacked) 921 + } 922 + recordPullSource := &tangled.RepoPull_Source{ 923 + Branch: sourceBranch, 924 + Repo: &fork.AtUri, 925 + Sha: sourceRev, 926 + } 927 + 928 + s.createPullRequest(w, r, f, user, title, body, targetBranch, patch, sourceRev, pullSource, recordPullSource, isStacked) 921 929 } 922 930 923 931 func (s *Pulls) createPullRequest( ··· 934 942 ) { 935 943 if isStacked { 936 944 // creates a series of PRs, each linking to the previous, identified by jj's change-id 937 - s.createStackedPulLRequest( 945 + s.createStackedPullRequest( 938 946 w, 939 947 r, 940 948 f, ··· 1049 1057 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pullId)) 1050 1058 } 1051 1059 1052 - func (s *Pulls) createStackedPulLRequest( 1060 + func (s *Pulls) createStackedPullRequest( 1053 1061 w http.ResponseWriter, 1054 1062 r *http.Request, 1055 1063 f *reporesolver.ResolvedRepo, ··· 1566 1574 if pull.IsBranchBased() { 1567 1575 recordPullSource = &tangled.RepoPull_Source{ 1568 1576 Branch: pull.PullSource.Branch, 1577 + Sha: sourceRev, 1569 1578 } 1570 1579 } 1571 1580 if pull.IsForkBased() { ··· 1573 1582 recordPullSource = &tangled.RepoPull_Source{ 1574 1583 Branch: pull.PullSource.Branch, 1575 1584 Repo: &repoAt, 1585 + Sha: sourceRev, 1576 1586 } 1577 1587 } 1578 1588
+1 -1
appview/repo/index.go
··· 133 133 for _, c := range commitsTrunc { 134 134 shas = append(shas, c.Hash.String()) 135 135 } 136 - pipelines, err := rp.getPipelineStatuses(repoInfo, shas) 136 + pipelines, err := getPipelineStatuses(rp.db, repoInfo, shas) 137 137 if err != nil { 138 138 log.Printf("failed to fetch pipeline statuses: %s", err) 139 139 // non-fatal
+2 -2
appview/repo/repo.go
··· 139 139 for _, c := range repolog.Commits { 140 140 shas = append(shas, c.Hash.String()) 141 141 } 142 - pipelines, err := rp.getPipelineStatuses(repoInfo, shas) 142 + pipelines, err := getPipelineStatuses(rp.db, repoInfo, shas) 143 143 if err != nil { 144 144 log.Println(err) 145 145 // non-fatal ··· 304 304 305 305 user := rp.oauth.GetUser(r) 306 306 repoInfo := f.RepoInfo(user) 307 - pipelines, err := rp.getPipelineStatuses(repoInfo, []string{result.Diff.Commit.This}) 307 + pipelines, err := getPipelineStatuses(rp.db, repoInfo, []string{result.Diff.Commit.This}) 308 308 if err != nil { 309 309 log.Println(err) 310 310 // non-fatal
+3 -2
appview/repo/repo_util.go
··· 105 105 // grab pipelines from DB and munge that into a hashmap with commit sha as key 106 106 // 107 107 // golang is so blessed that it requires 35 lines of imperative code for this 108 - func (rp *Repo) getPipelineStatuses( 108 + func getPipelineStatuses( 109 + d *db.DB, 109 110 repoInfo repoinfo.RepoInfo, 110 111 shas []string, 111 112 ) (map[string]db.Pipeline, error) { ··· 116 117 } 117 118 118 119 ps, err := db.GetPipelineStatuses( 119 - rp.db, 120 + d, 120 121 db.FilterEq("repo_owner", repoInfo.OwnerDid), 121 122 db.FilterEq("repo_name", repoInfo.Name), 122 123 db.FilterEq("knot", repoInfo.Knot),
+7 -1
lexicons/pulls/pull.json
··· 51 51 "source": { 52 52 "type": "object", 53 53 "required": [ 54 - "branch" 54 + "branch", 55 + "sha" 55 56 ], 56 57 "properties": { 57 58 "branch": { 58 59 "type": "string" 59 60 }, 61 + "sha": { 62 + "type": "string", 63 + "minLength": 40, 64 + "maxLength": 40 65 + }, 60 66 "repo": { 61 67 "type": "string", 62 68 "format": "at-uri"