-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Kartikey Mamgain <[email protected]>
- Loading branch information
1 parent
da804d7
commit 17196bc
Showing
5 changed files
with
117 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package main | ||
|
||
var projects = "redhat-developer" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | ||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= | ||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= | ||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= | ||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= | ||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||
github.com/google/go-github/v57 v57.0.0 h1:L+Y3UPTY8ALM8x+TV0lg+IEBI+upibemtBD8Q9u7zHs= | ||
github.com/google/go-github/v57 v57.0.0/go.mod h1:s0omdnye0hvK/ecLvpsGfJMiRt85PimQh4oygmLIxHw= | ||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= | ||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= | ||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= | ||
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= | ||
github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc= | ||
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= | ||
github.com/shurcooL/githubv4 v0.0.0-20240120211514-18a1ae0e79dc h1:vH0NQbIDk+mJLvBliNGfcQgUmhlniWBDXC79oRxfZA0= | ||
github.com/shurcooL/githubv4 v0.0.0-20240120211514-18a1ae0e79dc/go.mod h1:zqMwyHmnN/eDOZOdiTohqIUKUrTFX62PNlu7IJdu0q8= | ||
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 h1:17JxqqJY66GmZVHkmAsGEkcIu0oCe3AM420QDgGwZx0= | ||
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466/go.mod h1:9dIRpgIY7hVhoqfe0/FcYp0bpInZaT7dc3BYOprrIUE= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= | ||
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= | ||
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= | ||
golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ= | ||
golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= | ||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= | ||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= | ||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= | ||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= | ||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,94 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
|
||
gogi "github.com/google/go-github/v57/github" | ||
"github.com/gorilla/mux" | ||
"github.com/urfave/negroni" | ||
"github.com/shurcooL/githubv4" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
func HandleWebhook(w http.ResponseWriter, r *http.Request) { | ||
var req gogi.Issue | ||
json.NewDecoder(r.Body).Decode(&req) | ||
fmt.Println(req) | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
w.Write([]byte(`{"test": "ok}`)) | ||
} | ||
func CallGithubApi() { | ||
|
||
func Handler(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
w.Write([]byte(`{"test": "ok}`)) | ||
} | ||
src := oauth2.StaticTokenSource( | ||
&oauth2.Token{AccessToken: os.Getenv("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\")"` | ||
} | ||
|
||
func route() (n *negroni.Negroni, rt *mux.Router) { | ||
router := mux.NewRouter() | ||
err := client.Query(context.Background(), &q, nil) | ||
if err != nil { | ||
// Handle error. | ||
} | ||
fmt.Println(q.Repository.Description) | ||
printJSON(q) | ||
|
||
router.HandleFunc("/", Handler).Methods("GET") | ||
router.HandleFunc("/", HandleWebhook).Methods("POST") | ||
n = negroni.New(negroni.NewRecovery(), negroni.NewLogger()) | ||
return n, router | ||
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("open-connectors"), | ||
} | ||
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) | ||
} | ||
} | ||
func main() { | ||
|
||
n, router := route() | ||
n.UseHandler(router) | ||
n.Run(":8080") | ||
// printJSON prints v as JSON encoded with indent to stdout. It panics on any error. | ||
func printJSON(v interface{}) { | ||
w := json.NewEncoder(os.Stdout) | ||
w.SetIndent("", "\t") | ||
err := w.Encode(v) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func main() { | ||
CallGithubApi() | ||
} |
Binary file not shown.