From 5f16d003a8dc343aaf9b5dd0b7d862aa441f6cff Mon Sep 17 00:00:00 2001 From: Kartikey-star Date: Tue, 26 Mar 2024 13:34:04 +0530 Subject: [PATCH 1/2] code cleanup Signed-off-by: Kartikey-star --- main.go | 172 +------------------------------------------------------- 1 file changed, 2 insertions(+), 170 deletions(-) diff --git a/main.go b/main.go index a6ef40a..172760f 100644 --- a/main.go +++ b/main.go @@ -27,8 +27,8 @@ var ciUpload = flag.Bool("ci", false, "upload CI build data to Logilica") func main() { flag.Parse() if *planningUpload { - // client := CreateClient() - // LogilicaUploadPlanningData(client) + client := CreateClient() + LogilicaUploadPlanningData(client) fmt.Println("Upload Planning data") } if *ciUpload { @@ -471,174 +471,6 @@ func GetSprintInformation(gitbhubProjectId string, client *http.Client) SprintIn return sprintInformation } -func CallGithubGraphqlApi() { - p := os.Getenv("DPROD_TOKEN") - fmt.Println("TOKEN:", p) - client := oauth2.NewClient( - context.TODO(), - oauth2.StaticTokenSource( - &oauth2.Token{AccessToken: os.Getenv("DPROD_TOKEN")}, - )) - - query := `{ - node(id: "{{.Val}}") { - ... on ProjectV2 { - fields(first: {{.Id}}) { - nodes { - ... on ProjectV2Field { - id - name - } - ... on ProjectV2IterationField { - id - name - configuration { - iterations { - startDate - id - } - } - } - ... on ProjectV2SingleSelectField { - id - name - options { - id - name - } - } - } - } - } - } - }` - - // parametes to the query - ids := Parameters{"PVT_kwDOAFmk9s4ACTx2"} - tmpl, err := template.New("new").Parse(query) - buf := &bytes.Buffer{} - err = tmpl.Execute(buf, ids) - if err != nil { - panic(err) - } - gqlMarshalled, err := json.Marshal(graphQLRequest{Query: buf.String()}) - if err != nil { - panic(err) - } - resp, err := client.Post("https://api.github.com/graphql", "application/json", strings.NewReader(string(gqlMarshalled))) - b, _ := httputil.DumpResponse(resp, true) - fmt.Println(string(b)) -} - -func CallGithubApi() { - - src := oauth2.StaticTokenSource( - &oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")}, - ) - httpClient := oauth2.NewClient(context.Background(), src) - - client := githubv4.NewClient(httpClient) - - var q struct { - Repository struct { - Description string - Name string - } `graphql:"repository(owner: \"open-connectors\", name: \"open-connectors\")"` - } - - err := client.Query(context.Background(), &q, nil) - if err != nil { - // Handle error. - } - fmt.Println(q.Repository.Description) - - var query struct { - Repository struct { - Issue struct { - ID githubv4.ID - Reactions struct { - ViewerHasReacted githubv4.Boolean - } `graphql:"reactions(content:$reactionContent)"` - } `graphql:"issue(number:$issueNumber)"` - } `graphql:"repository(owner:$repositoryOwner,name:$repositoryName)"` - } - variables := map[string]interface{}{ - "repositoryOwner": githubv4.String("shurcooL-test"), - "repositoryName": githubv4.String("test-repo"), - "issueNumber": githubv4.Int(2), - "reactionContent": githubv4.ReactionContentThumbsUp, - } - err = client.Query(context.Background(), &q, variables) - if err != nil { - fmt.Println(err) - } - fmt.Println("already reacted:", query.Repository.Issue.Reactions.ViewerHasReacted) - - var listquery struct { - Organization struct { - Projectv2 struct { - Nodes []struct { - Id string - Title string - } - } `graphql:"projectsV2(first: 20)"` - } `graphql:"organization(login: $orgname)"` - } - variables = map[string]interface{}{ - "orgname": githubv4.String("containers"), - } - err = client.Query(context.Background(), &listquery, variables) - if err != nil { - fmt.Println(err) - } - nodes := listquery.Organization.Projectv2.Nodes - for _, node := range nodes { - fmt.Println(node.Id) - fmt.Println(node.Title) - } - - type ( - ProjectV2IterationFieldFragment struct { - id string - name string - configuration struct { - iterations struct { - startDate string - id string - } - } - } - ProjectV2SingleSelectFieldFragment struct { - id string - name string - options struct { - id string - name string - } - } - ) - - var projquery struct { - Node struct { - fields struct { - Nodes []struct { - Id string - Title string - } `graphql:"... on ProjectV2Field "` - ProjectV2IterationFieldFragment `graphql:"... on ProjectV2IterationField "` - ProjectV2SingleSelectFieldFragment `graphql:"... on ProjectV2SingleSelectField "` - } `graphql:"... on ProjectV2"` - } `graphql:"node(id:\"PVT_kwDOAFmk9s4AB47o\")"` - } - // variables = map[string]interface{}{ - // "id": githubv4.String("PVT_kwDOAFmk9s4AB47o"), - // } - err = client.Query(context.Background(), &projquery, nil) - if err != nil { - fmt.Println(err) - } -} - func UploadPlanningData(projectId string, payload []Planning) { postBody, _ := json.Marshal(payload) logilicaUrl := fmt.Sprintf("https://logilica.io/api/import/v1/pm/%v/issues/create", projectId) From 28c248ca13a91c69748ef632a7107202b94d552e Mon Sep 17 00:00:00 2001 From: Kartikey-star Date: Tue, 26 Mar 2024 13:35:59 +0530 Subject: [PATCH 2/2] code cleanup Signed-off-by: Kartikey-star --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 172760f..2c4c6c6 100644 --- a/main.go +++ b/main.go @@ -27,8 +27,8 @@ var ciUpload = flag.Bool("ci", false, "upload CI build data to Logilica") func main() { flag.Parse() if *planningUpload { - client := CreateClient() - LogilicaUploadPlanningData(client) + // client := CreateClient() + // LogilicaUploadPlanningData(client) fmt.Println("Upload Planning data") } if *ciUpload {