forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.go
More file actions
41 lines (33 loc) · 1.24 KB
/
http.go
File metadata and controls
41 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package view
import (
"encoding/base64"
"fmt"
"github.com/cli/cli/api"
"github.com/cli/cli/internal/ghrepo"
"github.com/cli/cli/pkg/cmd/workflow/shared"
)
func getWorkflowContent(client *api.Client, repo ghrepo.Interface, workflow *shared.Workflow) (string, error) {
path := fmt.Sprintf("repos/%s/contents/%s", ghrepo.FullName(repo), workflow.Path)
type Result struct {
Content string
}
var result Result
err := client.REST(repo.RepoHost(), "GET", path, nil, &result)
if err != nil {
return "", err
}
// TODO NB
// Because any random person can open a PR adding a workflow and that
// workflow by default shows up in the list of workflows for a repo, it's
// possible to try and request content for a workflow that doesn't actually
// exist in the base repo, but instead exists on a fork with the same branch
// name. This results in a 404. It's hard to justify doing work to make this
// not 404 as it seems to just be a spam loophole. Further, I'm not even sure
// /how/ to make it not 404 since workflows don't report what repo they
// originate from.
decoded, err := base64.StdEncoding.DecodeString(result.Content)
if err != nil {
return "", fmt.Errorf("failed to decode workflow file: %w", err)
}
return string(decoded), nil
}