From e584b835f290270af78538013634f348d6cc7398 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Thu, 20 Feb 2020 20:12:02 -0500 Subject: [PATCH] Get the last events * technically this isn't crawling all events - If someone complains that the last force push event is outside the last event page and within the timeframe view and doesn't want to use a tighter timeframe, I can fix this code to actually crawl all of the events (the code is able to do so fairly trivially), but I'm hoping on average that this shortcut is ok. --- check-pull-requests.sh | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/check-pull-requests.sh b/check-pull-requests.sh index f7a8163f6..9fbce97c3 100755 --- a/check-pull-requests.sh +++ b/check-pull-requests.sh @@ -38,15 +38,46 @@ cat "$pulls" | jq -c '.[]'|jq -c -r '{ base_sha: .base.sha, clone_url: .head.repo.clone_url, merge_commit_sha: .merge_commit_sha, - updated_at: .updated_at, + created_at: .created_at, + issue_url: .issue_url, commits_url: .commits_url, comments_url: .comments_url } | @base64' > "$escaped" +get_created_from_events() { + rm -f "$headers" + created_at=$(curl -s -S \ + -H "Authorization: token $GITHUB_TOKEN" \ + --header "Content-Type: application/json" \ + -D "$headers" \ + "$1" | + jq -M -r '[ .[]|select (.event=="head_ref_force_pushed") ][-1].created_at') + if [ "$created_at" = "null" ]; then + created_time=0 + else + created_time=$(date_to_epoch $created_at) + fi + if [ -e "$headers" ]; then + next_url=$(perl -ne 'next unless s/^Link: //;s/,\s+/\n/g; print "$1" if /<(.*)>; rel="last"/' $headers) + rm -f "$headers" + if [ -n "$next_url" ]; then + other_time=$(get_created_from_events "$next_url") + if [ "$created_time" -lt "$other_time" ]; then + created_time=$other_time + fi + fi + fi + echo "$created_time" +} + for a in $(cat "$escaped"); do echo "$a" | base64 --decode | jq -r . > $pull - updated_at=$(cat $pull | jq -r .updated_at) - age=$(( $start - $(date_to_epoch $updated_at) )) + issue_url=$(cat $pull | jq -r .issue_url) + created_at=$(get_created_from_events "${issue_url}/events") + if [ "$created_at" -eq 0 ]; then + created_at=$(date_to_epoch $(cat $pull | jq -r .created_at)) + fi + age=$(( $start - $created_at )) if [ $age -gt $time_limit ]; then continue fi