Skip to content

Commit

Permalink
md5
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Jan 22, 2024
1 parent d8eb0d6 commit cd055ca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
15 changes: 9 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ runs:
if: ${{inputs.pr_comment != 'true' && inputs.destroy != 'true'}}
shell: bash
run: |
curl -sLk \
curl -sLk --fail \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: ${{ github.token }}' \
Expand All @@ -103,14 +103,17 @@ runs:
if: ${{inputs.pr_comment == 'true' && steps.branch-name.outputs.is_default == 'false' && steps.branch-name.outputs.base_ref_branch != ''}}
shell: bash
run: |
curl -sLk \
response=$(curl -sLk \
-X GET \
-H 'Content-Type: application/json' \
"${{inputs.host}}/embed/${{github.repository_owner}}/${{ github.event.repository.name }}?type=${{ inputs.type }}&branch=${{ steps.branch-name.outputs.current_branch }}&base_branch=${{ steps.branch-name.outputs.base_ref_branch }}" > comment_body.txt
-w "%{http_code}" \
"${{inputs.host}}/pr?org=${{github.repository_owner}}&repo=${{ github.event.repository.name }}&type=${{ inputs.type }}&branch=${{ steps.branch-name.outputs.current_branch }}&base_branch=${{ steps.branch-name.outputs.base_ref_branch }}" \
-o comment_body.txt)
echo "PR_HTTP_RESPONSE=$response" >> $GITHUB_ENV
# Comment on PR if it is a pull req
# Comment on PR if it is a pull req and the status code is 201
- name: Comment on PR if it is a pull req
if: ${{inputs.pr_comment == 'true' && steps.find-pull-request.outputs.number != '' && steps.branch-name.outputs.base_ref_branch != ''}}
if: ${{inputs.pr_comment == 'true' && steps.find-pull-request.outputs.number != '' && steps.branch-name.outputs.base_ref_branch != '' && env.PR_HTTP_RESPONSE == '201'}}
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ steps.find-pull-request.outputs.number }}
Expand All @@ -129,7 +132,7 @@ runs:
if: ${{inputs.destroy == 'true'}}
shell: bash
run: |
curl -sLk \
curl -sLk --fail \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: ${{ github.token }}' \
Expand Down
2 changes: 1 addition & 1 deletion app/pkg/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (g *Github) VerifyGithubToken(token, orgName, repoName, commit string) erro
}

// look up cache, don't call Github API if it's already authenticated
cacheKey := []byte(fmt.Sprintf("%s/%s/%s", orgName, repoName, token))
cacheKey := []byte(MD5(fmt.Sprintf("%s/%s/%s", orgName, repoName, token)))
ret, err := g.cache.Get(cacheKey)
if err == nil && string(ret) == "true" {
return nil
Expand Down
7 changes: 7 additions & 0 deletions app/pkg/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package pkg

import (
"crypto/md5"
"encoding/hex"
"strconv"
)

Expand Down Expand Up @@ -52,3 +54,8 @@ func TakeFirst(s string, n int) string {
}
return s[:n]
}

func MD5(text string) string {
hash := md5.Sum([]byte(text))
return hex.EncodeToString(hash[:])
}

0 comments on commit cd055ca

Please sign in to comment.