I'm trying to get dependencyGraphManifests of a particular branch only, such as the default branch, I'm not really sure if this is even possible.
Here is my full query:
query orgRepos {
organization(login: "octokit") {
id
repositories(
first: 2
orderBy: {field: CREATED_AT, direction: ASC}
) {
edges {
node {
defaultBranchRef {
name
repository {
url
name
dependencyGraphManifests(withDependencies: true) {
totalCount
edges {
node {
blobPath
dependencies {
nodes {
packageName
requirements
}
}
}
}
}
}
}
}
}
}
}
}
But the response returns every manifest file.
Here is a simplified response:
"node": {
"defaultBranchRef": {
"name": "main",
"repository": {
"url": "https://github.com/octokit/octokit.js",
"name": "octokit.js",
"dependencyGraphManifests": {
"totalCount": 7,
"edges": [
{
"node": {
"blobPath": "/octokit/octokit.js/blob/main/package-lock.json"
}
},
{
"node": {
"blobPath": "/octokit/octokit.js/blob/main/package.json"
}
},
{
"node": {
"blobPath": "/octokit/octokit.js/blob/main/docs/package.json"
}
},
{
"node": {
"blobPath": "/octokit/octokit.js/blob/main/.github/workflows/release.yml"
}
},
{
"node": {
"blobPath": "/octokit/octokit.js/blob/main/.github/workflows/test.yml"
}
},
{
"node": {
"blobPath": "/octokit/octokit.js/blob/main/.github/workflows/update-prettier.yml"
}
}
]
}
}
}
}
It also worth noting that some of the blobpaths return invalid paths, such as /octokit/octokit.js/blob/main/docs/package.json, which doesn't actually exists on the default branch(its on a different branch). Is this a bug?
Related
Hi I am trying to update nested filed , but couldn't able to do so.
Here is the sample data,
[{
"_id": {
"$oid": "632ec4128f567511dcd80ed9"
},
"company_id": 1,
"contact_id": 1001,
"roles_to_be_accepted": {
"ROLE#04": {
"assigned_data": {
"assigned_3HFui": {
"is_idle": false,
"send_for_acceptance_date": 1664009233,
"action_date": ""
},
"assigned_b1J9t": {
"is_idle": false,
"send_for_acceptance_date": 1664009233,
"action_date": ""
}
}
},
"ROLE#02": {
"assigned_data": {
"assigned_uPJI1": {
"is_idle": false,
"send_for_acceptance_date": 1664009233,
"action_date": ""
}
}
}
}
}]
Now I want to update that is_idle field to true. I have tried in this way
let query = { contact_id: 1, company_id: 1001};
const db = this.client.db("dbname");
const col= db.collection("collection_name");
col.update(query, {
'$set': { "roles_to_be_accepted.assigned_data.is_idle": true }
});
I am trying to get the list of issues by their ids from Github using graphql, but looks like I am missing something or its not possible.
query ($ids:['517','510']!) {
repository(owner:"owner", name:"repo") {
issues(last:20, states:CLOSED) {
edges {
node {
title
url
body
author{
login
}
labels(first:5) {
edges {
node {
name
}
}
}
}
}
}
}
}
The above query is giving me response as below,
{
"errors": [
{
"message": "Parse error on \"'\" (error) at [1, 14]",
"locations": [
{
"line": 1,
"column": 14
}
]
}
]
}
Kindly help me identify if its possible or that I am doing something wrong here.
You can use aliases in order to build a single request requesting multiple issue object :
{
repository(name: "material-ui", owner: "mui-org") {
issue1: issue(number: 2) {
title
createdAt
}
issue2: issue(number: 3) {
title
createdAt
}
issue3: issue(number: 10) {
title
createdAt
}
}
}
Try it in the explorer
which gives :
{
"data": {
"repository": {
"issue1": {
"title": "Support for ref's on Input component",
"createdAt": "2014-10-15T15:49:13Z"
},
"issue2": {
"title": "Unable to pass onChange event to Input component",
"createdAt": "2014-10-15T16:23:28Z"
},
"issue3": {
"title": "Is it possible for me to make this work if I'm using React version 0.12.0?",
"createdAt": "2014-10-30T14:11:59Z"
}
}
}
}
This request can also be simplified using fragments to prevent repetition:
{
repository(name: "material-ui", owner: "mui-org") {
issue1: issue(number: 2) {
...IssueFragment
}
issue2: issue(number: 3) {
...IssueFragment
}
issue3: issue(number: 10) {
...IssueFragment
}
}
}
fragment IssueFragment on Issue {
title
createdAt
}
The request can be built programmatically, such as in this example python script :
import requests
token = "YOUR_TOKEN"
issueIds = [2,3,10]
repoName = "material-ui"
repoOwner = "mui-org"
query = """
query($name: String!, $owner: String!) {
repository(name: $name, owner: $owner) {
%s
}
}
fragment IssueFragment on Issue {
title
createdAt
}
"""
issueFragments = "".join([
"""
issue%d: issue(number: %d) {
...IssueFragment
}""" % (t,t) for t in issueIds
])
r = requests.post("https://api.github.com/graphql",
headers = {
"Authorization": f"Bearer {token}"
},
json = {
"query": query % issueFragments,
"variables": {
"name": repoName,
"owner": repoOwner
}
}
)
print(r.json()["data"]["repository"])
I don't think you can fetch for issues and pass in an array of integers for their ids.
But you can search for a single issue by id like so (this works for me)
query ($n: Int!) {
repository(owner:"owner", name:"repo-name") {
issue (number: $n) {
state
title
author {
url
}
}
}
}
where $n is {"n": <your_number>} defined.
If you have an array of ids, then you can just make multiple queries to GitHub.
Sadly, with this approach, you cannot specify what the state of the issue to be. But I think the logic is that once you know the issue Id, you shouldn't care what state it is, since you have that exact id.
How can I know given an closed issue, if it was closed through a pull request, specifically through a fork pull request, and how can I get the Id of the fork?
I've been reading in the issues/pull request/events API docs but haven't found anything.
It's possible using GraphQL API v4 using timelineItems and filtering on event with state CLOSED_EVENT
{
repository(name: "material-ui", owner: "mui-org") {
issue(number: 19641) {
timelineItems(itemTypes: CLOSED_EVENT, last: 1) {
nodes {
... on ClosedEvent {
createdAt
closer {
...on PullRequest {
baseRefName
baseRepository {
nameWithOwner
}
headRefName
headRepository {
nameWithOwner
}
}
}
}
}
}
}
}
}
Try it in the explorer
The closer field contains the source of the closing :
via pull request: PullRequest
via commit messages: Commit
or via the closed button: null
The following requests are example for the 3 types of closing
Closing via pull request
This pull request closed this issue
{
repository(name: "material-ui", owner: "mui-org") {
issue(number: 19641) {
timelineItems(itemTypes: CLOSED_EVENT, last: 1) {
nodes {
... on ClosedEvent {
createdAt
closer {
__typename
}
}
}
}
}
}
}
Output
{
"data": {
"repository": {
"issue": {
"timelineItems": {
"nodes": [
{
"createdAt": "2020-05-20T09:06:11Z",
"closer": {
"__typename": "PullRequest"
}
}
]
}
}
}
}
}
Closing via commit message
This commit closed this issue
{
repository(name: "rubinius", owner: "rubinius") {
issue(number: 1536) {
timelineItems(itemTypes: CLOSED_EVENT, last: 1) {
nodes {
... on ClosedEvent {
createdAt
closer {
__typename
}
}
}
}
}
}
}
Output
{
"data": {
"repository": {
"issue": {
"timelineItems": {
"nodes": [
{
"createdAt": "2012-01-30T22:33:11Z",
"closer": {
"__typename": "Commit"
}
}
]
}
}
}
}
}
Closing via button
This issue was closed via the close button :
{
repository(name: "rubinius", owner: "rubinius") {
issue(number: 3830) {
timelineItems(itemTypes: CLOSED_EVENT, last: 1) {
nodes {
... on ClosedEvent {
createdAt
closer {
__typename
}
}
}
}
}
}
}
Output
{
"data": {
"repository": {
"issue": {
"timelineItems": {
"nodes": [
{
"createdAt": "2020-02-02T22:31:05Z",
"closer": null
}
]
}
}
}
}
}
I am using the GitHub graphql for getting the sponsor information of a user. While I am able to get the sponsors for a particular user, I am unable to get the sponsorship-tier information for the sponsors. The graphql query that I have written is as follows:
{
user(login: <<loginID>>) {
name
sponsorshipsAsMaintainer(first: 1) {
totalCount
nodes {
createdAt
privacyLevel
tier {
createdAt
name
description
}
sponsor {
login
}
}
}
}
}
The results i get for a user are as follows. Ideally, in the query I was hoping to get the tier information but the result returns a null for the tier field.
{
"data": {
"user": {
"name": "XXX",
"sponsorshipsAsMaintainer": {
"totalCount": 11,
"nodes": [
{
"createdAt": "2020-02-16T10:39:14Z",
"privacyLevel": "PUBLIC",
"tier": null,
"sponsor": {
"login": "XXX"
}
}
]
}
}
}
}
Any help or information to get the tier information for a sponsor would be appreciated. Thank you very much.
To date tier is still null and I haven't figured out what's the issue with that.
However I managed to fetch the tiers information using the following query:
query getTiers($login: String!) {
user(login: $login) {
sponsorshipsAsSponsor(first: 1) {
nodes {
sponsorable {
sponsorsListing {
tiers(first: 5) {
nodes {
id
}
}
}
}
}
}
}
}
I'm using the following query to look up sponsors, and I only get tier information for my own tiers. I assume the viewer's databaseId must match the sponsorable databaseId to see this information
query {
user(login: "${login}") {
sponsorshipsAsSponsor(first: 100) {
nodes {
privacyLevel
tier {
monthlyPriceInDollars
}
sponsorable {
... on User {
databaseId
}
... on Organization {
databaseId
}
}
}
}
}
}
Here is a user that is sponsoring three other projects besides mine (I replaced the other project's databaseIds)
{
"data": {
"user": {
"sponsorshipsAsSponsor": {
"nodes": [
{
"privacyLevel": "PUBLIC",
"tier": {
"monthlyPriceInDollars": 3
},
"sponsorable": {
"databaseId": 220908 <--- Me
}
},
{
"privacyLevel": "PUBLIC",
"tier": null,
"sponsorable": {
"databaseId": 1
}
},
{
"privacyLevel": "PUBLIC",
"tier": null,
"sponsorable": {
"databaseId": 1
}
},
{
"privacyLevel": "PUBLIC",
"tier": null,
"sponsorable": {
"databaseId": 1
}
}
]
}
}
}
}
I have users array with their name,
var users = [{'name':'zulekha'}, {'name':'deepika'}];
I am fetching worklogged by each user from jira APIs. So I am getting object like this.
var worklogResult = {
"issues": [
{
"fields": {
"worklog": {
"worklogs": [
{
"author": {
"name": "zulekha",
},
"timeSpentSeconds": 180
},
{
"author": {
"name": "deepika",
},
"timeSpentSeconds": 210
}
]
}
}
},
{
"fields": {
"worklog": {
"worklogs": [
{
"author": {
"name": "deepika",
},
"timeSpentSeconds": 140
}
]
}
}
},
{
"fields": {
"worklog": {
"worklogs": [
{
"author": {
"name": "zulekha",
},
"timeSpentSeconds": 600,
}
]
}
}
},
{
"fields": {
"worklog": {
"worklogs": []
}
}
}
]
}
Now I want to match worklogResult with users in such a way that I can get following output.
output = [{'name':'zulekha','timeSpentSeconds':780}, {'name':'deepika', 'timeSpentSeconds':350}]
Can anyone suggest me how to achieve this?
use _.flatMap to flat nested objects
_.chain(worklogResult.issues)
.flatMap('fields.worklog.worklogs')
.thru(function(spents) {
return _.map(users, function(user) {
return _.merge(user, {
timeSpentSeconds: _.chain(spents)
.filter(['author.name', user.name])
.map('timeSpentSeconds')
.sum()
.value()
})
})
})
.value()