How to get the comments from a GitHub pull request using GitHub API? - github-api

I am trying to get the comments on a pull request using GitHub API, for example:
https://api.github.com/repos/mapra99/members-only/pulls/1/comments
But it returns an empty array.
The same if I try to use the review comments endpoint:
https://api.github.com/repos/mapra99/members-only/issues/1/comments
Although there is a comment on that pull request:
https://github.com/mapra99/members-only/pull/1
How can I get the comment that is on that pull request using GitHub API? Why is it not possible to get if from any of those endpoints?

In fact, this is not a comment but a review :
Pull Request Reviews are groups of Pull Request Review Comments on the
Pull Request, grouped together with a state and optional body comment.
You can get the reviews using :
https://api.github.com/repos/mapra99/members-only/pulls/1/reviews
Or using GraphQL v4 to get reviews & comments :
{
repository(owner: "mapra99", name: "members-only") {
pullRequest(number: 1) {
reviews(first: 100) {
nodes {
body
}
}
comments(first: 100) {
nodes {
body
}
}
}
}
}

Related

Fetch the name of Linked Entry in Contentful API

I'm using Contentful API to get the details of all the entries in a Space, is there a way to fetch the name of 'linked entry/entries' to a particular entry? In this case, i'm fetching all the entries with the content_type = HorizontalImageCard and then that each entry has link to other entries(could be a link to an Asset or link to different Contentul entry), and i would like to get the name of such entries, attaching the screenshot of what i'm looking for, in the screenshot there's a Linked Entry called 'Jennifer Test', how do i fetch that name?
let fetchRes = fetch("https://preview.contentful.com/spaces/{space_id}/environments/ca/entries/{entry_id}?access_token=vOKxCDyhU8gLUsU4FR5tgdwQVe3arwfJzFTCloi2sjM&content_type=HorizontalImageCard");
Did you try with the GraphQL API? I didn't get a chance to try it out with the REST API, but I was able to get the result with the GraphQL API. Here's an example query:
{
userCollection(preview:true) {
items {
name
linkedFrom {
blogArticleCollection {
items {
title
}
}
}
}
}
}
The User content type is linked in the Blog Article content type. This method allows me to list all those references. Hope this helps :)

Incomplete API response for getUsers

I'm implementing an API integration for DocuSign, and I'm currently hitting the following endpoint: /v2/organizations/{organizationId}/users
The documentaton for this: https://developers.docusign.com/docs/admin-api/reference/users/users/getusers/#response200_docusign.api.organizations.web.models.restapi.v2.response.organizationuserresponse
The documentation is showing a response field, user_status. However, when I call the API, I get a response as follows:
{
"users":[
{
"id":"xxx-xxx-xxx-xxx-xxx",
"user_name":"Xxxx",
"first_name":"",
"last_name":"Xxxx",
"membership_status":"active",
"email":"xxxx#gmail.com",
"membership_created_on":"2021-07-30T02:24:20.243",
"membership_id":"xxxx-xxxx-xxxx-xxxx-xxxx"
},
{
"id":"yyy-yyy-yyy-yyy-yyy",
"user_name":"Yyyyy",
"first_name":"Yyyyy",
"last_name":"2",
"membership_status":"active",
"email":"yyyyyyy#yyy.yyy",
"membership_created_on":"2021-07-30T02:26:59.313",
"membership_id":"yyy-yyy-yyy-yyy-yyy"
},
{
"id":"zzz-zzz-zzz-zzz-zzz",
"user_name":"Zzzzz",
"first_name":"Zzzz",
"last_name":"Zzzz",
"membership_status":"active",
"email":"zzz#zzz-zzz.net",
"membership_created_on":"2021-07-15T04:05:18.803",
"membership_id":"zzz-zzz-zzz-zzz-zzz"
}
],
"paging":{
"result_set_size":3,
"result_set_start_position":0,
"result_set_end_position":2,
"total_set_size":3
}
}
As you can see, we have no user_status. Do we need to send any request parameters, to expand the response, or has this field been removed from the API response without being updated on the API documentation?
Or, could I assume that the user is active, if it appears in the API response, with a membership_status of active?
Thank you very much!
membership_status is probably what you're looking for.
there's no such thing as user_status because a user can be a member of multiple accounts and each membership can have a different status.
Here is a useful diagram:

Is there a way to query when I contributed to a pull request with submitting review with github-api v3 Search API?

I'm trying to query GitHub Search API to fetch my contributions that are made by submitting reviews on pull requests.
On my profile page on GitHub, there's "Contribution Activity" and there's a pane "Reviewed X pull requests in Y repositories" in it. When I expand it, I see a list of my contributions made by review submitting, and it includes information such as "when I made the contribution". I confirmed this is not the date of pull request creaqted, merged, updated.
Is there a way to fetch "when I made the review contribution" via GitHub Search API?
reviewed date on profile page
You can use GraphQL Api v4 and filter the reviews by author for each pull request from the search query :
{
search(query: "reviewed-by:eps1lon is:pr updated:2019-01-01..2019-01-31", type: ISSUE, first: 100) {
issueCount
nodes {
... on PullRequest {
repository {
nameWithOwner
}
number
reviews(author: "eps1lon", last: 1) {
nodes {
createdAt
lastEditedAt
publishedAt
body
}
}
}
}
}
}
Try it in the explorer
You will need to iterate over all the results if there is more than 100 results
To format your result & sort by date you can use a json parser like jq. Using bash, jq & curl :
user=eps1lon
date_range=2019-01-01..2019-01-31
token=YOUR_TOKEN
curl -s -H "Authorization: bearer $token" -d '
{
"query": "query {search(query: \"reviewed-by:'"$user"' is:pr updated:'"$date_range"'\", type: ISSUE, first: 100) {issueCount nodes {... on PullRequest {repository {nameWithOwner}number reviews(author: '"$user"', last: 1) {nodes {createdAt lastEditedAt publishedAt body}}}}}}"
}
' https://api.github.com/graphql | \
jq '[
.data.search.nodes[] |
{
repo:.repository.nameWithOwner,
number:.number,
createdAt:.reviews.nodes[0].createdAt,
publishedAt:.reviews.nodes[0].publishedAt,
lastEditedAt: .reviews.nodes[0].lastEditedAt
} |
select (.createdAt >= "2019-01-01") ] |
sort_by(.createdAt) |
reverse'

Get GitHub avatar from email or name

I'm trying to get the GitHub user picture (avatar) from users of GitHub.
I've found these API:
https://avatars.githubusercontent.com/<username>
https://avatars.githubusercontent.com/u/<userid>
But I can't find a way to get the avatar from the user email or the user display name.
I can't find documentation about that.
Is there some similar URL API to get what I'm looking for?
You can append .png to the URL for the User's profile to get redirected to their avatar. You can add the query param size to specify a size smaller than the default of 460px wide (i.e. it won't allow larger than 460).
Examples:
https://github.com/twbs.png
https://github.com/npm.png?size=200
https://github.com/github.png?size=40
https://developer.github.com/v3/users/#get-a-single-user
Use the /users/:user endpoint. Should be under avatar_url in the returned json.
For example, my avatar_url can be found by hitting this url.
Edit
There is another way I can think of that is kind of roundabout. Since GitHub uses Gravatar, if you know the email associated with the account, do an md5 hash of the lowercase, stripped email address and construct a url like http://www.gravatar.com/avatar/[md5_here].
This is an old post but nobody has proposed Github Search Users API with scope field :
using in:email : https://api.github.com/search/users?q=bmartel+in%3Aemail
using in:username : https://api.github.com/search/users?q=Bertrand+Martel+in%3Ausername
Or using new Graphql API v4 :
{
search(type: USER, query: "in:email bmartel", first: 1) {
userCount
edges {
node {
... on User {
avatarUrl
}
}
}
}
}
Using GraphQL API v4, this will work too
Query (for username)-
{
user(login: "username") {
avatarUrl
}
}
Response -
{
"data": {
"user": {
"avatarUrl": "https://avatars1.githubusercontent.com/u/..."
}
}
}
GitHub avatar can be accessed through https://avatars.githubusercontent.com/u/YOUR_USER_ID
Optionally, you can modify the size at the end like so https://avatars.githubusercontent.com/u/YOUR_USER_ID?s=460

how to get "my pull requests" from github api?

If you look at: http://developer.github.com/v3/pulls/ it shows you how to get pull requests for a given repository.
How do we get "my pull requests" from the GitHub API similar to the data displayed on the GitHub dashboard?
I asked Github directly. A rep told me to use the search endpoint. Search for issues owned by you that are open and of type pr.
https://api.github.com/search/issues?q=state%3Aopen+author%3Adavidxia+type%3Apr
If you're using a python client lib like Pygithub you can do
issues = gh.search_issues('', state='open', author='davidxia', type='pr')
You can also use GraphQL API v4 to get all your pull requests :
{
user(login: "bertrandmartel") {
pullRequests(first: 100, states: OPEN) {
totalCount
nodes {
createdAt
number
title
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
Try it in the explorer
or using viewer :
{
viewer {
pullRequests(first: 100, states: OPEN) {
totalCount
nodes {
createdAt
number
title
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
First you have to realize that you must authenticate using either Basic Authentication or a token. Next you have to realize that there is no simple way to do this so you will have to be clever.
To be specific, if you probe https://api.github.com/issues, you'll notice that the issues there have a hash called pull_request which should have 3 URLs: html, diff, and patch. All three will be non-null if the issue is also a Pull Request. (Pro-tip: They're the same thing as far as GitHub is concerned…sort of.)
If you iterate over your issues and filter for ones where those attributes are not null, then you'll have your pull requests.

Resources