Skip to content

Commit 5527e6f

Browse files
committed
removing id token dependency
1 parent 7bcd319 commit 5527e6f

File tree

3 files changed

+10
-216
lines changed

3 files changed

+10
-216
lines changed

apiclient.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,21 @@ func (apiclient *ApiClient) performRequest(method, url string, headers map[strin
3333
return nil, err
3434
}
3535

36-
for k, v := range headers {
37-
req.Header.Add(k, v)
36+
if headers != nil {
37+
for key, value := range headers {
38+
req.Header.Add(key, value)
39+
}
3840
}
3941

4042
return apiclient.Client.Do(req)
4143
}
4244

43-
func (apiclient *ApiClient) SubmitCodeReviewRequest(oidcToken string, prDetails *PullRequestDetails) (*CodeReviewRequestResponse, error) {
45+
func (apiclient *ApiClient) SubmitCodeReviewRequest(prDetails *PullRequestDetails) (*CodeReviewRequestResponse, error) {
4446
url := fmt.Sprintf("%s/codereview/submit", apiclient.ApiBaseURI)
4547
jsonData, _ := json.Marshal(prDetails)
4648

4749
headers := map[string]string{
48-
"Content-Type": "application/json; charset=UTF-8",
49-
"Authorization": fmt.Sprintf("Bearer %s", oidcToken),
50+
"Content-Type": "application/json; charset=UTF-8",
5051
}
5152

5253
resp, err := apiclient.performRequest("POST", url, headers, bytes.NewBuffer(jsonData))
@@ -69,14 +70,10 @@ func (apiclient *ApiClient) SubmitCodeReviewRequest(oidcToken string, prDetails
6970
return &codeReviewRequestResponse, nil
7071
}
7172

72-
func (apiclient *ApiClient) GetCodeReviewComments(oidcToken string, request *CodeReviewRequestResponse) (*CodeReviewCommentsResponse, error) {
73+
func (apiclient *ApiClient) GetCodeReviewComments(request *CodeReviewRequestResponse) (*CodeReviewCommentsResponse, error) {
7374
url := fmt.Sprintf("%s/codereview/comments?fullreponame=%s&codereviewid=%s", apiclient.ApiBaseURI, request.FullRepoName, request.CodeReviewID)
7475

75-
headers := map[string]string{
76-
"Authorization": fmt.Sprintf("Bearer %s", oidcToken),
77-
}
78-
79-
resp, err := apiclient.performRequest("GET", url, headers, nil)
76+
resp, err := apiclient.performRequest("GET", url, nil, nil)
8077
if err != nil {
8178
return nil, err
8279
}

main.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ const (
4040
OperationStatusError = "Error"
4141
)
4242

43-
func getTokenRemainingValidity(timestamp interface{}) float64 {
44-
if validity, ok := timestamp.(float64); ok {
45-
tm := time.Unix(int64(validity), 0)
46-
remainder := time.Until(tm)
47-
return remainder.Seconds()
48-
}
49-
return 0
50-
}
51-
5243
func getGitHubClient() (*github.Client, context.Context, error) {
5344
pat := os.Getenv("INPUT_PAT")
5445
if len(pat) == 0 {
@@ -159,22 +150,12 @@ func getPullRequestDetailsFromEnvironment(isDebugMode bool) (*PullRequestDetails
159150

160151
func submitPRDetailsAndGetCodeFeedback(prDetails *PullRequestDetails, isDebugMode bool) (bool, error) {
161152
responseReceived := false
162-
audience := APIEndpoint
163-
oidcClient, err := DefaultOIDCClient(audience)
164-
if err != nil {
165-
return responseReceived, fmt.Errorf("error generating OIDC auth token. error:%v", err)
166-
}
167-
168-
actionsJWT, exp, err := getActionsJWTAndExp(oidcClient, isDebugMode)
169-
if err != nil {
170-
return responseReceived, fmt.Errorf("error generating OIDC auth token. error:%v", err)
171-
}
172153

173154
apiClient := ApiClient{
174155
Client: &http.Client{},
175156
ApiBaseURI: APIEndpoint + "/v1/app/",
176157
}
177-
response, err := apiClient.SubmitCodeReviewRequest(actionsJWT.Value, prDetails)
158+
response, err := apiClient.SubmitCodeReviewRequest(prDetails)
178159
if err != nil {
179160
return responseReceived, fmt.Errorf("error submitting code review request: %v", err)
180161
}
@@ -185,15 +166,7 @@ func submitPRDetailsAndGetCodeFeedback(prDetails *PullRequestDetails, isDebugMod
185166
var reviewComments *CodeReviewCommentsResponse
186167

187168
for i := 0; i < 20 && !responseReceived; i++ {
188-
remainder := getTokenRemainingValidity(exp)
189-
if remainder < 60 {
190-
githubactions.Infof("Renewing OIDC token as it's only valid for %f", remainder)
191-
actionsJWT, exp, err = getActionsJWTAndExp(oidcClient, isDebugMode)
192-
if err != nil {
193-
return responseReceived, fmt.Errorf("error renewing OIDC token. Error: %v", err)
194-
}
195-
}
196-
reviewComments, err = apiClient.GetCodeReviewComments(actionsJWT.Value, response)
169+
reviewComments, err = apiClient.GetCodeReviewComments(response)
197170
if err != nil {
198171
return responseReceived, fmt.Errorf("error retrieving code review comments: %v", err)
199172
}

oidc.go

Lines changed: 0 additions & 176 deletions
This file was deleted.

0 commit comments

Comments
 (0)