Github GraphQl - How to get a list of commits between tags - graphql

With Github GraphQL I want to answer the question:
What commits have been merged into master between releases/tags?
The result should be similar to the results for this question Get commit list between tags in Git if I were to do it on the command line.
I'm using the developer explorer and wondering if I will be able to do this with a single query or if I will need several. I tried the following but it does not give me the commits between tags that have not been tagged, just the tagged commits.
{
repository(owner: "CoolCompany", name: "awesome-new-ui") {
refs(refPrefix: "refs/tags/", first: 2, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) {
edges {
node {
id
name
target {
oid
... on Commit {
author {
date
email
name
}
message
}
}
}
}
}
}
}

#lee-dohm from the Github GraphQL community helped me arrive at a solution which is posted here
I can paste my solution here as well. It seems this problem is not solve-able with a single query, but it can be done with 2 that work in conjunction with each other:
Step 1: Get the most recent release information. You could modify this for tags as well.
{
repository(owner: "CoolCompany", name: "awesome-ui") {
releases(last: 1) {
edges{
node{
tagName
createdAt
}
}
}
}
}
Step 2: Use the value from the createdAt (associated with the release or tag) and do this:
{
repository(owner: "CoolCompany", name: "awesome-ui") {
nameWithOwner
object(expression: "master") {
... on Commit {
oid
history(first: 100, since: "$createdAtDate") {
nodes {
oid
messageHeadline
author {
user {
login
}
}
committedDate
}
}
}
}
}
}

Related

How can I get the project name for a timelog issue entry using the project ID from a Gitlab GraphQL query

I'm using the graphql explorer for gitlab and I'm trying to get timelog entries for a given user (as below).
The response gives me a projectId which I assume I'd have to use in a subsequent query (I don't believe I can get it in the same query?), but the project object doesn't let me find the project by ID, only fullpath.
Am I correct in understanding that I would need to use the projects query and provide the id there? In trying that (query below), I just get the error 12345678 is not a valid GitLab ID. (obviously I'm using a real ID given previously).
So, two points/questions I guess:
The timelog entry provides a projectId which I can't use in either the project or projects query to get the project name?
I can't just return the project name directly in the same query as the original user timelog one?
Any thoughts greatly appreciated.
{
users(usernames: ["user1"]) {
nodes {
id
username
timelogs(startDate: "2022-05-03T09:00:00") {
nodes {
issue {
projectId
}
timeSpent
}
}
}
}
}
{
projects(ids:[12345678]) {
nodes {
name
}
}
}
I don't know if this helps, but I use:
{
group(fullPath: "groupname") {
name
timelogs(startTime: "2022-04-01", endTime: "2022-04-30", username: "roberto") {
pageInfo {
hasNextPage
endCursor
}
nodes {
user {
username
}
issue {
iid
webUrl
state
projectId
title
}
spentAt
timeSpent
summary
note {
body
url
}
}
}
}
}

Shopify Admin API, graphQL, create draft order - add products

This is my fist time creating an order. From what I understand you need to create a draft order - add products, price, email, notes etc. I am just creating a test query now to see how it works and it tells me "Add at least 1 product". I am trying to add a product, but I dont know how. I have been messing around and reading and cant figure it out.
This is my query:
mutation draftOrderCreate {
draftOrderCreate(input: {email: "123abc#hotmail.com"}) {
draftOrder {
id
order {
id
}
status
}
userErrors {
field
message
}
}
}
If anyone can give me an example on how to add products to this would be great. Thanks.
You can create an draft order like so:
mutation draftOrderCreate($items: DraftOrderInput!) {
draftOrderCreate(input: $items) {
draftOrder {
id
order {
id
}
status
}
userErrors {
field
message
}
}
}
query variables:
{
"items": {
"email": "123abc#hotmail.com",
"lineItems": [
{
"variantId": "gid://shopify/ProductVariant/32231002996788",
"quantity": 1
}
]
}
}
Or if you don't want to use query variables you can pass the whole object as the input:
mutation draftOrderCreate {
draftOrderCreate(input: {email: "123abc#hotmail.com", lineItems: [{variantId: "gid://shopify/ProductVariant/32231002996788", quantity: 1}]}) {
draftOrder {
id
order {
id
}
status
}
userErrors {
field
message
}
}
}

How to query data from GitHub Discussions using GitHub's GraphQL API

I want to query the data from https://github.com/prisma/prisma/discussions via GitHub's GraphQL API but I don't know how to access it.
GitHub Discussions are a beta feature that's currently available only on a few repos, prisma/prisma being one of them. I would have expected that I can query the data in a similar fashion to querying issues and pull requests of a repo:
{
repository(
owner: "prisma"
name: "prisma"
) {
pullRequests(first: 5 orderBy: {
field: CREATED_AT,
direction: DESC
}) {
edges {
node {
title
}
}
}
issues(first: 5 orderBy: {
field: CREATED_AT,
direction: DESC
}) {
edges {
node {
title
}
}
}
}
}
I'm basically looking for a query that would allow me to do this:
{
repository(
owner: "prisma"
name: "prisma"
) {
# this doesn't work
discussions(first: 5 orderBy: {
field: CREATED_AT,
direction: DESC
}) {
edges {
node {
title
}
}
}
}
}
But such a discussions property doesn't exist on the Repository type in the GitHub API.
EDIT (Dec 8, 2020): I learned from the GitHub team that the data is not yet available via the public GraphQL API but they're working on releasing it soon. I'll leave the question open until it's available.

using graphql github api to get commit information by Id

I would like to get commit details for a specific commit given that I already have the commit id
for example, if I know the commit id is
12762b76cba8ac4623a6c16e1fe60efafa3b7d1c and the repo is ruby/ruby
how do I get the committedDate and author email?
You can try using a cursor as an edge type, as in this thread:
{
repository(owner: "octocat", name: "Hello-World") {
first: object(expression: "master") {
... on Commit {
history(path: "README", last: 1, before: "762941318ee16e59dabbacb1b4049eec22f0d303 1") {
edges {
node {
committedDate
oid
author
{
email
}
}
}
}
}
}
}
}
you can test it using this explorer https://developer.github.com/v4/explorer/

How do I query the GitHub v4 API for directory contents at a certain tag?

How do I query the GitHub API v4 for the contents of a certain directory of a repository at a certain tag?
This is the best I've come up with so far:
query {
repository(owner:"example", name:"example") {
refs(refPrefix: "tags") {
}
}
}
From this post, you can get the GitObject with object to filter on branch:/path/folder and print the Tree. The following will get the tree from gson folder from tag gson-2.4 and print name, type and mode :
query {
repository(owner:"google", name:"gson") {
object(expression: "gson-2.4:gson") {
... on Tree{
entries{
name
type
mode
}
}
}
}
}

Resources