Skip to content

Commit 04445b6

Browse files
committed
Issue PoC
1 parent b16b07b commit 04445b6

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

tools/flakeguard/cmd/make_issue.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// TODO: This is a PoC, need to be cleaned up much more before game time
2+
package cmd
3+
4+
import (
5+
"context"
6+
"fmt"
7+
"os"
8+
9+
"github.com/shurcooL/githubv4"
10+
"github.com/spf13/cobra"
11+
"golang.org/x/oauth2"
12+
)
13+
14+
var MakeIssueCmd = &cobra.Command{
15+
Use: "make-issue",
16+
Short: "Make an issue to skip identified flaky tests",
17+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
18+
if githubToken == "" {
19+
githubToken = os.Getenv("GITHUB_TOKEN")
20+
}
21+
if githubToken == "" {
22+
return fmt.Errorf("GitHub token not set, set GITHUB_TOKEN env var or use --githubToken flag")
23+
}
24+
return nil
25+
},
26+
RunE: makeIssue,
27+
}
28+
29+
func makeIssue(cmd *cobra.Command, args []string) error {
30+
// Set up GitHub client
31+
tok := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: githubToken})
32+
token := oauth2.NewClient(context.Background(), tok)
33+
graphqlClient := githubv4.NewClient(token)
34+
35+
// https://docs.github.com/en/copilot/using-github-copilot/coding-agent/using-copilot-to-work-on-an-issue#assigning-an-issue-to-copilot-via-the-github-api
36+
37+
// Get suggestedActors from the API to check if Copilot is enabled
38+
var suggestedActorsQuery struct {
39+
Repository struct {
40+
SuggestedActors struct {
41+
Nodes []struct {
42+
Login string
43+
Typename string `graphql:"__typename"`
44+
Bot struct {
45+
ID githubv4.ID
46+
} `graphql:"... on Bot"`
47+
User struct {
48+
ID githubv4.ID
49+
} `graphql:"... on User"`
50+
}
51+
} `graphql:"suggestedActors(capabilities: [CAN_BE_ASSIGNED], first: 100)"`
52+
} `graphql:"repository(owner: $owner, name: $name)"`
53+
}
54+
55+
variables := map[string]interface{}{
56+
"owner": githubv4.String("smartcontractkit"), // Replace with your repo owner
57+
"name": githubv4.String("chainlink"), // Replace with your repo name
58+
}
59+
60+
err := graphqlClient.Query(context.Background(), &suggestedActorsQuery, variables)
61+
if err != nil {
62+
return fmt.Errorf("failed to get suggested actors: %w", err)
63+
}
64+
65+
// Check if Copilot coding agent is enabled
66+
// If enabled, the first node will have login "copilot-swe-agent"
67+
copilotFound := false
68+
for _, actor := range suggestedActorsQuery.Repository.SuggestedActors.Nodes {
69+
if actor.Login == "copilot-swe-agent" {
70+
copilotFound = true
71+
break // Found it, no need to continue
72+
}
73+
}
74+
75+
if copilotFound {
76+
fmt.Println("✅ Copilot coding agent is available for this user and repository")
77+
} else {
78+
fmt.Println("❌ Copilot coding agent is not enabled for this user/repository")
79+
os.Exit(ErrorExitCode)
80+
}
81+
82+
return nil
83+
}
84+
85+
func init() {
86+
MakeIssueCmd.Flags().StringVarP(&githubToken, "githubToken", "t", "", "GitHub token to use for creating the issue (can be set with GITHUB_TOKEN env var)")
87+
}

tools/flakeguard/cmd/make_pr.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func makePR(cmd *cobra.Command, args []string) error {
156156
fmt.Print("Committing changes, tap your yubikey if it's blinking...")
157157
sha, err := flake_git.MakeSignedCommit(repoPath, fmt.Sprintf("Skips flaky %d tests: %s", len(testsToSkip), strings.Join(jiraTickets, ", ")), branchName, githubToken)
158158
if err != nil {
159+
fmt.Println()
159160
return fmt.Errorf("failed to commit changes: %w", err)
160161
}
161162
fmt.Printf(" %s ✅\n", sha)

tools/flakeguard/git/git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func MakeSignedCommit(repoPath, commitMessage, branch, githubToken string) (stri
278278
return "", err
279279
}
280280

281-
// Code mostly stolen from https://github.com/planetscale/ghcommit/tree/main
281+
// Inspired by https://github.com/planetscale/ghcommit/tree/main
282282

283283
// process added / modified files:
284284
worktree, err := repo.Worktree()

tools/flakeguard/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func init() {
4747
rootCmd.AddCommand(cmd.CreateTicketsCmd)
4848
rootCmd.AddCommand(cmd.SyncJiraCmd)
4949
rootCmd.AddCommand(cmd.MakePRCmd)
50+
rootCmd.AddCommand(cmd.MakeIssueCmd)
5051
}
5152

5253
func main() {

0 commit comments

Comments
 (0)