Github API: get a request for a specific release tag

Is it possible to get a list of pull requests (or just numbers) associated with the release tag?


I have been looking at all the Github API documentation all day and have tried different things, but I don’t see how to do it.

I don’t see that the draft request information is available when I get a commit via the API, even if there is an output request identifier and a link: https://github.com/octokit/octokit.rb/commit/1d82792d7d16457206418850a3ed0a0230defc81 (see link # 962 next to "master" in the upper left)

+4
source share
2 answers

( ) commit SHA API :

  • ( ), , ( , )
  • , compare
  • pull SHA. (*) sha, SHA:<commit sha>

(*) , 256 , API

, :

#!/bin/bash

current_tag="v4.8.0"
name_with_owner="octokit/octokit.rb"
access_token="YOUR_ACCESS_TOKEN"

tags=$(curl -s -H "Authorization: Token $access_token" \
            "https://api.github.com/repos/$name_with_owner/tags")
key=$(jq -r --arg current_tag $current_tag 'to_entries | .[] | select(.value.name == $current_tag) | .key' <<< "$tags")
previous_tag=$(jq -r --arg index $((key+1)) '.[$index | tonumber].name' <<< "$tags")

echo "compare between $previous_tag & $current_tag"

commits=$(curl -s -H "Authorization: Token $access_token" \
               "https://api.github.com/repos/$name_with_owner/compare/$previous_tag...$current_tag" | \
               jq -r '.commits[].sha')


# you can have a query of maximum of 256 character so we only process 17 sha for each request
count=0
max_per_request=17
while read sha; do
    if [ $count == 0 ]; then
        query="repo:$name_with_owner%20type:pr"
    fi
    query="$query%20SHA:%20${sha:0:7}"
    count=$((count+1))
    if ! (($count % $max_per_request)); then
        echo "https://api.github.com/search/issues?q=$query"
        curl -s -H "Authorization: Token $access_token" \
            "https://api.github.com/search/issues?q=$query" | jq -r '.items[].html_url'
        count=0
    fi
done <<< "$commits"
+1

Ruby:

  • octokit gem
  • fix feat
  • :

:

require 'octokit'
Client = Octokit::Client.new(access_token: YOUR_GITHUB_TOKEN)

def getCommitsForTag(repo, tagName)
  previousTag = getPreviousTag repo, tagName
  (Client.compare repo, previousTag.name, tagName).commits
end

def getPreviousTag(repo, tagName)
  tags = Client.tags repo
  tags.each_with_index { |tag, index|
    if tag.name == tagName
      return tags[index+1]
    end
  }
end

def filterCommitsByPrefix(commits, commitPrefixArray)
  filteredArray = []
  commits.each { |commit|
    commitPrefixArray.each { |commitPrefix|
      if commit.commit.message.start_with?(commitPrefix)
        filteredArray.push(commit)
      end
    }
  }
  filteredArray
end

def getPullRequestsByCommits(commits)
  query = "SHA:"
  commits.each { |commit| 
    query += "#{commit.sha},"
  }
  Client.search_issues query
end


def getPullRequestsForTag(repo, tag)
  commitsForTag = getCommitsForTag repo, tag
  fixCommits = filterCommitsByPrefix commitsForTag, ['fix']
  featCommits = filterCommitsByPrefix commitsForTag, ['feat']
  {
    fixes: getPullRequestsByCommits(fixCommits).items,
    features: getPullRequestsByCommits(featCommits).items
  }
end

#Execute it like this:
pullRequestsForTag = getPullRequestsForTag 'octokit/octokit.rb', 'v4.8.0'

puts "Fix pull requests:"
puts pullRequestsForTag[:fixes]
puts "Feat pull requests:"
puts pullRequestsForTag[:features]
0

Source: https://habr.com/ru/post/1692982/


All Articles