MCPcopy Index your code
hub / github.com/1Password/for-open-source / Approve

Method Approve

script/approver.go:20–93  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18}
19
20func (a *Approver) Approve() {
21 if err := a.application.SetApprover(); err != nil {
22 a.logErrorAndExit("could not set application approver", err)
23 }
24
25 if err := a.gitHub.Init(); err != nil {
26 a.logErrorAndExit("could not initialize GitHub client", err)
27 }
28
29 if err := a.gitHub.InitIssue(); err != nil {
30 a.logErrorAndExit("could not initialize GitHub issue", err)
31 }
32
33 if *a.gitHub.Issue.State == "closed" {
34 a.logErrorAndExit(
35 "script run on closed issue",
36 errors.New(*a.gitHub.Issue.State),
37 )
38 }
39
40 if !a.gitHub.IssueHasLabel(LabelStatusApproved) {
41 a.logErrorAndExit(
42 fmt.Sprintf("script run on issue that does not have required '%s' label", LabelStatusApproved),
43 fmt.Errorf("issue has labels %v", a.gitHub.Issue.Labels),
44 )
45 }
46
47 a.application.Parse(a.gitHub.Issue)
48
49 if !a.application.IsValid() {
50 a.logErrorAndExit(
51 "script run on issue with invalid application data",
52 errors.New(a.renderProblems()),
53 )
54 }
55
56 // The reviewer may remove this label themselves, but
57 // let's double check and remove it if they haven't
58 if a.gitHub.IssueHasLabel(LabelStatusReviewing) {
59 if err := a.gitHub.RemoveIssueLabel(LabelStatusReviewing); err != nil {
60 a.logErrorAndExit(
61 fmt.Sprintf("could not remove issue label '%s'", LabelStatusReviewing),
62 err,
63 )
64 }
65 }
66
67 if err := a.gitHub.CommitNewFile(
68 filepath.Join("data", a.application.FileName()),
69 a.application.GetData(),
70 fmt.Sprintf("Added \"%s\" to program", a.application.Project.Name),
71 ); err != nil {
72 a.logErrorAndExit(
73 "could not create commit",
74 err,
75 )
76 }
77

Callers 1

mainFunction · 0.95

Calls 15

logErrorAndExitMethod · 0.95
renderProblemsMethod · 0.95
getApprovalMessageMethod · 0.95
createSentryEventMethod · 0.95
SetApproverMethod · 0.80
InitMethod · 0.80
InitIssueMethod · 0.80
IssueHasLabelMethod · 0.80
ParseMethod · 0.80
IsValidMethod · 0.80
RemoveIssueLabelMethod · 0.80
CommitNewFileMethod · 0.80

Tested by

no test coverage detected