+36
-2
api/tangled/cbor_gen.go
+36
-2
api/tangled/cbor_gen.go
···
7008
7008
}
7009
7009
7010
7010
cw := cbg.NewCborWriter(w)
7011
-
fieldCount := 2
7011
+
fieldCount := 3
7012
7012
7013
7013
if t.Repo == nil {
7014
7014
fieldCount--
7015
7015
}
7016
7016
7017
7017
if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil {
7018
+
return err
7019
+
}
7020
+
7021
+
// t.Sha (string) (string)
7022
+
if len("sha") > 1000000 {
7023
+
return xerrors.Errorf("Value in field \"sha\" was too long")
7024
+
}
7025
+
7026
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("sha"))); err != nil {
7027
+
return err
7028
+
}
7029
+
if _, err := cw.WriteString(string("sha")); err != nil {
7030
+
return err
7031
+
}
7032
+
7033
+
if len(t.Sha) > 1000000 {
7034
+
return xerrors.Errorf("Value in field t.Sha was too long")
7035
+
}
7036
+
7037
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Sha))); err != nil {
7038
+
return err
7039
+
}
7040
+
if _, err := cw.WriteString(string(t.Sha)); err != nil {
7018
7041
return err
7019
7042
}
7020
7043
···
7116
7139
}
7117
7140
7118
7141
switch string(nameBuf[:nameLen]) {
7119
-
// t.Repo (string) (string)
7142
+
// t.Sha (string) (string)
7143
+
case "sha":
7144
+
7145
+
{
7146
+
sval, err := cbg.ReadStringWithMax(cr, 1000000)
7147
+
if err != nil {
7148
+
return err
7149
+
}
7150
+
7151
+
t.Sha = string(sval)
7152
+
}
7153
+
// t.Repo (string) (string)
7120
7154
case "repo":
7121
7155
7122
7156
{
+1
api/tangled/repopull.go
+1
api/tangled/repopull.go
+1
-1
appview/db/artifact.go
+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
+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{
···
162
163
func (p *Pull) LatestPatch() string {
163
164
latestSubmission := p.Submissions[p.LastRoundNumber()]
164
165
return latestSubmission.Patch
166
+
}
167
+
168
+
func (p *Pull) LatestSha() string {
169
+
latestSubmission := p.Submissions[p.LastRoundNumber()]
170
+
return latestSubmission.SourceRev
165
171
}
166
172
167
173
func (p *Pull) PullAt() syntax.ATURI {
+21
-11
appview/pulls/pulls.go
+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 {
···
826
819
if !patchutil.IsPatchValid(patch) {
827
820
s.pages.Notice(w, "pull", "Invalid patch format. Please provide a valid diff.")
828
821
return
822
+
}
823
+
824
+
pullSource := &db.PullSource{
825
+
Branch: sourceBranch,
826
+
}
827
+
recordPullSource := &tangled.RepoPull_Source{
828
+
Branch: sourceBranch,
829
+
Sha: comparison.Rev2,
829
830
}
830
831
831
832
s.createPullRequest(w, r, f, user, title, body, targetBranch, patch, sourceRev, pullSource, recordPullSource, isStacked)
···
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
+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
+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
+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
+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"
60
+
},
61
+
"sha": {
62
+
"type": "string",
63
+
"minLength": 40,
64
+
"maxLength": 40
59
65
},
60
66
"repo": {
61
67
"type": "string",