Github API: Getting topics of a Github repository - github

Github API documentation give instructions to filter repositories by topics.
Is there a way to use the API to get the topics from a specific repo?

You can do this with the Github GraphQL API
Query:
{
repository(owner: "twbs", name: "bootstrap") {
repositoryTopics(first: 10) {
edges {
node {
topic {
name
}
}
}
}
}
}
This will return the first 10 topics and the name for each as shown below.
Response:
{
"data": {
"repository": {
"repositoryTopics": {
"edges": [
{
"node": {
"topic": {
"name": "css"
}
}
},
{
"node": {
"topic": {
"name": "bootstrap"
}
}
},
{
"node": {
"topic": {
"name": "javascript"
}
}
},
{
"node": {
"topic": {
"name": "html"
}
}
}
]
}
}
}
}
Test it out in the GitHub GraphQL Explorer

You can do this easily with Github API (it's currently in "preview mode"):
curl -H "Accept: application/vnd.github.mercy-preview+json" https://api.github.com/repos/twbs/bootstrap/topics
{
"names": [
"css",
"bootstrap",
"javascript",
"html",
"jekyll-site",
"scss",
"css-framework",
"sass"
]
}
You need to include extra header Accept: application/vnd.github.mercy-preview+json.
There is one "but", since it's in "preview mode" it's not supported for production use (please read "Note" and "Warning" sections in link below).
See also:
https://docs.github.com/en/rest/reference/repos#get-a-repository

I don't know that there is a way to just get the topics for a repository, but if you do a get for a repository, the repository json object that is returned will have a topics property that is an array of that repositories topics.
At the top of that page of documentation, you will notice that in order to have the topics returned you will need to add a specific header in your GET request: "Accept":"application/vnd.github.mercy-preview+json"
Hope this helps!

I faced similar problem, so I made a node module that only require one line of code to do that which is
var github_topics = require('github-topics');
var topics = github_topics.gettopics('url_of_repo');
for example
var topics = github_topics.gettopics('https://github.com/Aniket965/blog');
It will return array of topics of that github repository , link to that node module is NPM

I added the fetch with Accept Headers:
fetch("https://api.github.com/users/lucksp/repos",
{
method: "GET",
headers: {
Accept: "application/vnd.github.mercy-preview+json"
}
})

Related

Github GrapQL API returns only the last StatusContext for each context

I'm cross-posting the question from here.
I’m interested in knowing whether it’s possible to fetch all the statuses for all the contexts for a given reference using the GQL API.
The query that I’m currently doing is the following:
{
repository(owner: "owner", name: "name") {
pullRequests(headRefName: "head-ref", last: 1) {
nodes {
id
commits(first: 10) {
nodes {
commit {
oid
status {
contexts {
context
createdAt
id
description
state
}
}
}
}
}
}
}
}
}
This query returns a single status for each status context, and those are the last ones for each:
{
"data": {
"repository": {
"pullRequests": {
"nodes": [
{
"id": "some-id",
"commits": {
"nodes": [
{
"commit": {
"oid": "some-oid",
"status": {
"contexts": [
{
"context": "context-1",
"createdAt": "2021-07-06T21:28:26Z",
"id": "***",
"description": "Your tests passed!",
"state": "SUCCESS"
},
{
"context": "context-2",
"createdAt": "2021-07-06T21:25:26Z",
"id": "***",
"description": "Your tests passed!",
"state": "SUCCESS"
},
]
}
}
}
]
}
}
]
}
}
}
}
On the other hand, if I use the REST API with this query:
curl -i -u se7entyse7en:$(cat token) https://api.github.com/repos/owner/name/commits/some-oid/statuses
where some-oid is the corresponding retrieved with the GQL API, the output contains ALL the statuses. In particular, I can see all the statuses of context-1 and context-2 that happened before those that are returned by the GQL API.
It seems a limitation of the GQL schema given that StatusContext is a node instead of being a list of nodes. Basically, I expect StatusContext to be of type [Status!]! where Status represents a single status for the given context.
Am I missing something? Is this something expected to be changed in the future? Is the REST API the only option?
Thanks.
I opened a support ticket and this is the expected behavior indeed, there are no plans for changing it. The only solution is to use the REST API.
The link to the community forum is this one.

Which private repos have GitHub Pages

I want to downgrade my GitHub account to the free plan. GitHub warns me that I have one private repository that uses GitHub Pages - a feature that the free plan doesn't support. So I want to find this repo to see if it is problematic if it becomes public.
I can't find any way to even list my repos that use Github Pages, let alone the ones that are private.
Is there a way to do this?
Yes, simple via GraphQL API, with or without GraphQL API Explorer, (don't forget personal access token scope if using without the explorer,) if you don't have very much private repos.
Use query:
query {
viewer {
repositories (first:100, privacy: PRIVATE) {
nodes {
name
deployments (first: 1) {
nodes {
environment
}
}
}
}
}
}
Example result:
{
"data": {
"viewer": {
"repositories": {
"nodes": [
{
"name": "repo-without-pages",
"deployments": {
"nodes": []
}
},
{
"name": "repo-with-pages",
"deployments": {
"nodes": [
{
"environment": "github-pages"
}
]
}
}
]
}
}
}
}
Typically the only possible environment is github-pages. If you have more, change the above query.
Note GitHub GraphQL API has a limit: Values of first and last must be within 1-100. If you have more than 100, use:
repositories (first:100, privacy: PRIVATE) {
pageInfo {
endCursor
}
and after getting endCursor:
repositories (first:100, privacy: PRIVATE, after:"endCursorValue==") {
pageInfo {
endCursor
}
to paginate.

Is it possible to find the project boards an issue is associated with using the Github API?

I'm developing a Github webhook that gets notifications on issue updates.
These issues are associated to one of more Github Project Boards
The body payload shows this information related to the updated issue:
Nothing about issue association with project boards. Is there a way to get this information?
You can use GraphQL API to get that information using projectCards under the Issue object :
{
repository(name: "caipy-dashboard", owner: "bertrandmartel") {
issue(number: 26) {
title
projectCards {
nodes {
createdAt
column {
name
}
project {
name
body
}
}
}
}
}
}
Output :
{
"data": {
"repository": {
"issue": {
"title": "fix dead path in startover",
"projectCards": {
"nodes": [
{
"createdAt": "2017-08-28T05:47:49Z",
"column": {
"name": "Done"
},
"project": {
"name": "Startover",
"body": "Show epg / caipy events + startover modes"
}
}
]
}
}
}
}
}
Try it in the explorer

Media Response in Custom Payload (Dialogflow)

I'm trying to code a Media Response in a Custom Payload with no luck. I'm surely doing something wrong but I have no idea :) The Media Response does not show up when testing. (Please note that I'm trying this in an english action). Here's the JSON code:
{
"platform": "google",
"type": "custom_payload",
"payload": {
"google": {
"richResponse": {
"items": [
{
"mediaResponse": {
"mediaType": "AUDIO",
"mediaObjects": [
{
"name": "Exercises",
"description": "ex",
"largeImage": {
"url": "https://firebasestorage.googleapis.com/...",
"accessibilityText": "image..."
},
"contentUrl": "https://firebasestorage.googleapis.com/..."
}
]
}
}
]
}
}
}
}
UPDATE:
I've updated the JSON to something like this. But I get an error :"API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: ": Cannot find field."
{
"platform":"google",
"type":"custom_payload",
"payload":{
"google":{
"richResponse":{
"items":[
{
"simpleResponse":{
"textToSpeech":"Hey! Good to see you."
}
},
{
"mediaResponse":{
"mediaType":"AUDIO",
"mediaObjects":[
{
"name":"Exercises",
"description":"ex",
"largeImage":{
"url":"https://firebasestorage...",
"accessibilityText":"..."
},
"contentUrl":"https://firebasestorage.googleapis.com/..."
}
]
}
}
],
"suggestions":[
{
"title":"chips"
}
]
}
}
And here's the debug information:
{
"audioResponse": "//NExAARWG...",
"conversationToken": "GidzaW11bG...",
"debugInfo": {
"agentToAssistantDebug": {
"agentToAssistantJson": "{\"message\":\"Failed to parse Dialogflow response into AppResponse, exception thrown with message: Empty speech response\",\"apiResponse\":{\"id\":\"cd7204ac-ab80-42aa-9755-6123cbb938a6\",\"timestamp\":\"2018-03-11T09:02:35.827Z\",\"lang\":\"en-us\",\"result\":{},\"status\":{\"code\":200,\"errorType\":\"success\"},\"sessionId\":\"1520758955600\"}}"
},
"assistantToAgentDebug": {
"assistantToAgentJson": "{\"user\":{\"userId\":\"AA9douaa4XGkqtmcU_EDjPy7PQ_9\",\"locale\":\"en-US\",\"lastSeen\":\"2018-03-11T09:02:09Z\"},\"conversation\":{\"conversationId\":\"1520758955600\",\"type\":\"NEW\"},\"inputs\":[{\"intent\":\"actions.intent.MAIN\",\"rawInputs\":[{\"inputType\":\"VOICE\",\"query\":\"Talk to Zen Coach\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.MEDIA_RESPONSE_AUDIO\"},{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]},\"isInSandbox\":true,\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]}]}",
"curlCommand": "curl -v 'https://api.api.ai/api/integrations/google?token=0def1bb6be4b4bf2810ec68bf6f37a6a' -H 'Content-Type: application/json;charset=UTF-8' -H 'Google-Actions-API-Version: 2' -H 'Authorization: eyJhbGciOiJSUzI1NiIsImtpZCI6ImFjMmI2M2ZhZWZjZjgzNjJmNGM1MjhlN2M3ODQzMzg3OTM4NzAxNmIifQ.eyJhdWQiOiJ6ZW4tY29hY2giLCJhenAiOiI0OTYwOTIwOTE1NzEtMGNhY3VtczVkZ3F1OWpkM2k0dHZpOGFiOTVydXQ2NnQuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJleHAiOjE1MjA3NTkwNzUsImlzcyI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbSIsImp0aSI6IjY4NDc0NThhNTNhZGExODAxZjMwMjAyYjkxZGIyODZhMjk1NzA2YmIiLCJpYXQiOjE1MjA3NTg5NTUsIm5iZiI6MTUyMDc1ODY1NX0.e1cqg96F5L-BvD0yJz3UFgsnX_0TRox0Lu8R9K5NhhXcQVfC7mq1QwCqs2DGrUJGquGdW2GhzBU2lzf4ro2TUeieg4ozak1OmiYAMqtiCH0EodeHy59AXXqzb3a35YuD7CmSDu6qVQRfEp8uaaH2t-Sq9lUchudNOgjucip3ex9Rr2XacHm0qWtV69H1o-Yq5INl5HHR0kNqtEIsxUox961imKvDLN5s--F35yTbAhIWibr6OmaACyzSQW5X7OjrJ2781DSmEdYn73poDbuwMS9E2l9B-QTUHAIpUM5b4WqrFkD6XKALdf2pQFwZlRRhDzRiDKWLA-i1w-mcak0LWw' -A 'Mozilla/5.0 (compatible; Google-Cloud-Functions/2.1; +http://www.google.com/bot.html)' -X POST -d '{\"user\":{\"userId\":\"AA9douaa4XGkqtmcU_EDjPy7PQ_9\",\"locale\":\"en-US\",\"lastSeen\":\"2018-03-11T09:02:09Z\"},\"conversation\":{\"conversationId\":\"1520758955600\",\"type\":\"NEW\"},\"inputs\":[{\"intent\":\"actions.intent.MAIN\",\"rawInputs\":[{\"inputType\":\"VOICE\",\"query\":\"Talk to Zen Coach\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.MEDIA_RESPONSE_AUDIO\"},{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]},\"isInSandbox\":true,\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]}]}'"
},
"sharedDebugInfo": [
{
"name": "ResponseValidation",
"subDebugEntry": [
{
"debugInfo": "API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: \": Cannot find field.\".",
"name": "UnparseableJsonResponse"
}
]
}
]
},
"response": "Zen coach isn't responding right now. Try again soon.",
"visualResponse": {
"visualElements": []
}
}
Are you adding "platform":"google" and "type":"custom_payload" in the custom payload? If so, try removing that.
I made the following work with my Voice Metronome application:
{
"google":{
"richResponse":{
"items":[
{
"simpleResponse":{
"textToSpeech":"Hey! Good to see you."
}
},
{
"mediaResponse":{
"mediaType":"AUDIO",
"mediaObjects":[
{
"name":"Exercises",
"description":"ex",
"largeImage":{
"url":"http://res.freestockphotos.biz/pictures/17/17903-balloons-pv.jpg",
"accessibilityText":"..."
},
"contentUrl":"https://freepd.com/Chill/Chill Air.mp3"
}
]
}
}
],
"suggestions":[
{
"title":"chips"
}
]
}
}
}
The issue is that the richResponse property still needs to follow the rules of the RichResponse object. The first item in it must be a SimpleResponse object. (I haven't tested, but you can probably have that say nothing, but it is a good spot to have an introduction to your audio.)
The error message Failed to parse Dialogflow response into AppResponse, exception thrown with message: Empty speech response suggests that it might also be looking for a speech parameter on the top-level object in the response, which is what Dialogflow v1 expects to duplicate either the simpleResponse ssml or textToSpeech parameters. I'm not sure why that would appear if you're set to v2, but it sounds like something might be confused there. I would make sure you're using v1 and that you have a speech parameter.
Also keep in mind that the reviewers will look for suggestion chips about how to move the conversation forward during or after the audio if this isn't a final response.

Querying github project cards with graphql

I have a Project in Github with some columns, and I'm trying to locate cards (Issues) that are in the closed state.
With GraphQL I'm having trouble constructing a query that can filter the cards. Currently I have this query:
query {
organization(login:"org") {
project(number:3) {
columns(first:1){
nodes{
id,
name,
cards(first:1){
nodes{
content {
... on Issue {
url,
state
}
}
}
}
}
}
}
}
}
This returns the result:
{
"data": {
"organization": {
"project": {
"columns": {
"nodes": [
{
"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"name": "On Deck",
"cards": {
"nodes": [
{
"content": {
"url": "https://github.com/org/repo/issues/606",
"state": "OPEN"
}
}
]
}
}
]
}
}
}
}
}
What I have gathered thus far is that the "Project Cards" are "UNION" objects in GraphQL and I have no idea how to add filters to these unions.
Any suggestions?
Thank you!
I asked the same question on the GitHub Community forum. An admin wrote back:
The way that the GraphQL API is currently built, no, you can't filter project cards on the state of the issue that they're representing using only the query language. You would have to query all cards in the column and then filter it yourself.