Skip to content

Commit

Permalink
🐛 Returns errors properly and patch request handling
Browse files Browse the repository at this point in the history
  • Loading branch information
CryogenicPlanet committed Nov 5, 2021
1 parent 8052448 commit 5de116e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
18 changes: 12 additions & 6 deletions ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func checkPrComments() int64 {
client := github.NewClient(nil)
ctx := context.Background()

var response *github.Response
var response *http.Response

if checkIfPublic() {
// Public repo no need to proxy
Expand Down Expand Up @@ -87,7 +87,7 @@ func checkPrComments() int64 {

check(err)

response, err = client.BareDo(ctx, &http.Request{Method: "GET", URL: link})
response, err = http.Get(link.String())

check(err)
}
Expand All @@ -109,8 +109,8 @@ func checkPrComments() int64 {
}

func makePrComment(deployUrl string) {
setGithubRepoFromEnv()
setIssueNumberFromEnv()
// setGithubRepoFromEnv()
// setIssueNumberFromEnv()

ctx := context.Background()
ts := oauth2.StaticTokenSource(
Expand Down Expand Up @@ -151,9 +151,15 @@ func makePrComment(deployUrl string) {

check(err)

_, err = client.BareDo(ctx, &http.Request{Method: "GET", URL: link})
resp, err := http.Get(link.String())

check(err)
if err != nil {
fmt.Println("[WARN]", err)
}

if resp.StatusCode > 300 {
fmt.Println("Failed response", resp.Status, resp)
}

}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "depp-installer",
"version": "0.0.8",
"version": "0.0.8-patch-request-handling",
"description": " A fast unused and duplicate dependency checker ",
"repository": {
"type": "git",
Expand Down
10 changes: 10 additions & 0 deletions serverless/api/proxy/issueComments.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func Handler(w http.ResponseWriter, r *http.Request) {
fmt.Println(err)
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintln(w, "Could not parse issue number")
return
}

token, err := shared.GetInstallationToken(owner)
Expand All @@ -32,6 +33,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, err)
return

}

tokenCtx := context.Background()
Expand All @@ -49,6 +52,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, "Could not get issue data")
return

}

link, err := url.Parse(issueData.GetCommentsURL())
Expand All @@ -58,6 +63,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {

w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, "Could not get parse comment url")
return

}

response, err := tokenClient.BareDo(tokenCtx, &http.Request{URL: link})
Expand All @@ -66,6 +73,8 @@ func Handler(w http.ResponseWriter, r *http.Request) {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, "Could not get comments")
return

}

// issue, _, err := client.Issues.Get(tokenCtx, "cryogenicplanet", "cryogenicplanet.github.io", 49)
Expand All @@ -78,6 +87,7 @@ func Handler(w http.ResponseWriter, r *http.Request) {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, "Could not read response")
return
}

headers := response.Header.Clone()
Expand Down
1 change: 1 addition & 0 deletions serverless/api/proxy/updateComment.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func UpdateHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintln(w, "Could not get create/edit comment", err)
return
}

w.WriteHeader(http.StatusAccepted)
Expand Down

0 comments on commit 5de116e

Please sign in to comment.