tangled
alpha
login
or
join now
julien.rbrt.fr
/
tangled-core
forked from
tangled.org/core
0
fork
atom
Monorepo for Tangled — https://tangled.org
0
fork
atom
overview
issues
pulls
pipelines
appview: pulls: add check for knot caps
anirudh.fi
11 months ago
09c05893
36fd5706
+48
-2
3 changed files
expand all
collapse all
unified
split
appview
state
pull.go
signer.go
types
capabilities.go
+26
appview/state/pull.go
···
563
563
return
564
564
}
565
565
566
566
+
us, err := NewUnsignedClient(f.Knot, s.config.Dev)
567
567
+
if err != nil {
568
568
+
log.Println("failed to create unsigned client to %s: %v", f.Knot, err)
569
569
+
s.pages.Notice(w, "pull", "Failed to create a pull request. Try again later.")
570
570
+
return
571
571
+
}
572
572
+
573
573
+
caps, err := us.Capabilities()
574
574
+
if err != nil {
575
575
+
log.Println("error fetching knot caps", f.Knot, err)
576
576
+
s.pages.Notice(w, "pull", "Failed to create a pull request. Try again later.")
577
577
+
return
578
578
+
}
579
579
+
566
580
// Determine PR type based on input parameters
567
581
isPushAllowed := f.RepoInfo(s, user).Roles.IsPushAllowed()
568
582
isBranchBased := isPushAllowed && sourceBranch != "" && fromFork == ""
···
583
597
584
598
// Handle the PR creation based on the type
585
599
if isBranchBased {
600
600
+
if !caps.PullRequests.BranchSubmissions {
601
601
+
s.pages.Notice(w, "pull", "This knot doesn't support branch-based pull requests. Try another way?")
602
602
+
return
603
603
+
}
586
604
s.handleBranchBasedPull(w, r, f, user, title, body, targetBranch, sourceBranch)
587
605
} else if isForkBased {
606
606
+
if !caps.PullRequests.ForkSubmissions {
607
607
+
s.pages.Notice(w, "pull", "This knot doesn't support fork-based pull requests. Try another way?")
608
608
+
return
609
609
+
}
588
610
s.handleForkBasedPull(w, r, f, user, fromFork, title, body, targetBranch, sourceBranch)
589
611
} else if isPatchBased {
612
612
+
if !caps.PullRequests.PatchSubmissions {
613
613
+
s.pages.Notice(w, "pull", "This knot doesn't support patch-based pull requests. Send your patch over email.")
614
614
+
return
615
615
+
}
590
616
s.handlePatchBasedPull(w, r, f, user, title, body, targetBranch, patch)
591
617
}
592
618
return
+13
-2
appview/state/signer.go
···
351
351
return us.client.Do(req)
352
352
}
353
353
354
354
-
func (us *UnsignedClient) Capabilities(ownerDid, repoName string) (*http.Response, error) {
354
354
+
func (us *UnsignedClient) Capabilities() (*types.Capabilities, error) {
355
355
const (
356
356
Method = "GET"
357
357
Endpoint = "/capabilities"
···
362
362
return nil, err
363
363
}
364
364
365
365
-
return us.client.Do(req)
365
365
+
resp, err := us.client.Do(req)
366
366
+
if err != nil {
367
367
+
return nil, err
368
368
+
}
369
369
+
defer resp.Body.Close()
370
370
+
371
371
+
var capabilities types.Capabilities
372
372
+
if err := json.NewDecoder(resp.Body).Decode(&capabilities); err != nil {
373
373
+
return nil, err
374
374
+
}
375
375
+
376
376
+
return &capabilities, nil
366
377
}
367
378
368
379
func (us *UnsignedClient) Compare(ownerDid, repoName, rev1, rev2 string) (*http.Response, error) {
+9
types/capabilities.go
···
1
1
+
package types
2
2
+
3
3
+
type Capabilities struct {
4
4
+
PullRequests struct {
5
5
+
PatchSubmissions bool `json:"patch_submissions"`
6
6
+
BranchSubmissions bool `json:"branch_submissions"`
7
7
+
ForkSubmissions bool `json:"fork_submissions"`
8
8
+
} `json:"pull_requests"`
9
9
+
}