From 3c225444210d369e006d81491577b1bee5b84ce7 Mon Sep 17 00:00:00 2001 From: jgstew Date: Mon, 25 Sep 2023 17:25:34 -0400 Subject: [PATCH] add recipe to test github api limits --- .../ExampleGitHubTokenAPI.test.recipe.yaml | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Test-Recipes/ExampleGitHubTokenAPI.test.recipe.yaml diff --git a/Test-Recipes/ExampleGitHubTokenAPI.test.recipe.yaml b/Test-Recipes/ExampleGitHubTokenAPI.test.recipe.yaml new file mode 100644 index 0000000..5b58279 --- /dev/null +++ b/Test-Recipes/ExampleGitHubTokenAPI.test.recipe.yaml @@ -0,0 +1,43 @@ +--- +Description: Example recipe getting the github api limits +Identifier: com.github.jgstew.test.ExampleGitHubAPI +Input: + NAME: ExampleGitHubAPI +MinimumVersion: "2.3" +Process: + - Processor: com.github.jgstew.SharedProcessors/SharedUtilityMethods + + - Processor: FileFinder + Arguments: + # create a read only limited personal access token on GitHub.com + # set the expiration to 1 year + # put the token in this file: + pattern: "/Users/*/.autopkg_gh_token" + + - Processor: com.github.jgstew.SharedProcessors/FileTextSearcher + Arguments: + search_path: "%found_filename%" + file_search_results_var: "GITHUB_TOKEN" + # match all characters that are not whitespace: + search_pattern: '\S+' + first_result_only: True + + - Processor: URLTextSearcher + Arguments: + # example using gh command: `gh api --method GET /rate_limit` + url: https://api.github.com/rate_limit + curl_opts: ["-H", "Authorization: token %GITHUB_TOKEN%"] + # the GITHUB_API_LIMIT should be 5000: + re_pattern: '(?m)"rate":\s*{[\s\n\r]+"limit":\s*(?P\d+),[\s\n\r]+"used":\s*(?P\d+)' + # Example Match: + # "rate": { + # "limit": 5000, + # "used": 3, + # "remaining": 4997, + # "reset": 1677627218 + # } + + - Processor: EndOfCheckPhase + Arguments: + # clear token so it isn't saved in plist + GITHUB_TOKEN: ""