i am trying to get filename from github gist API, the below output which i get while calling the gist api.But the problem is how do i get the filename from the output. because filename is under files, and i want to display filename. So how do i do that. I am new to API so only able to display url, id, etc.
{
"url": "https://api.github.com/gists/41da54b03986886e1a4e57c8cdb38dc2",
"forks_url": "https://api.github.com/gists/41da54b03986886e1a4e57c8cdb38dc2/forks",
"commits_url": "https://api.github.com/gists/41da54b03986886e1a4e57c8cdb38dc2/commits",
"id": "41da54b03986886e1a4e57c8cdb38dc2",
"node_id": "MDQ6R2lzdDQxZGE1NGIwMzk4Njg4NmUxYTRlNTdjOGNkYjM4ZGMy",
"git_pull_url": "https://gist.github.com/41da54b03986886e1a4e57c8cdb38dc2.git",
"git_push_url": "https://gist.github.com/41da54b03986886e1a4e57c8cdb38dc2.git",
"html_url": "https://gist.github.com/41da54b03986886e1a4e57c8cdb38dc2",
"files": {
"telegram-white.svg": {
"filename": "telegram-white.svg",
"type": "image/svg+xml",
"language": "SVG",
"raw_url": "https://gist.githubusercontent.com/cmschandan/41da54b03986886e1a4e57c8cdb38dc2/raw/16b1aac41526997d87400f33ad9912d511faf7a4/telegram-white.svg",
"size": 1266
}
},
"public": true,
"created_at": "2020-12-11T12:58:59Z",
"updated_at": "2020-12-11T12:59:46Z",
"description": "",
"comments": 0,
"user": null,
"comments_url": "https://api.github.com/gists/41da54b03986886e1a4e57c8cdb38dc2/comments",
"owner": {
"login": "cmschandan",
"id": 21227329,
"node_id": "MDQ6VXNlcjIxMjI3MzI5",
"avatar_url": "https://avatars.githubusercontent.com/u/21227329?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/cmschandan",
"html_url": "https://github.com/cmschandan",
"followers_url": "https://api.github.com/users/cmschandan/followers",
"following_url": "https://api.github.com/users/cmschandan/following{/other_user}",
"gists_url": "https://api.github.com/users/cmschandan/gists{/gist_id}",
"starred_url": "https://api.github.com/users/cmschandan/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/cmschandan/subscriptions",
"organizations_url": "https://api.github.com/users/cmschandan/orgs",
"repos_url": "https://api.github.com/users/cmschandan/repos",
"events_url": "https://api.github.com/users/cmschandan/events{/privacy}",
"received_events_url": "https://api.github.com/users/cmschandan/received_events",
"type": "User",
"site_admin": false
},
"truncated": false
},
If you are using JavaScript then you can do something like this:
// `getGitHubGist` is a function that I assume you already
// implemented which fetches your desired gist.
const gist = await getGitHubGist();
// Get an array of filename strings
const filenames = Object.keys(gist.files);
// Get an array of all the file details
const files = Object.values(gist.files);
Related
There is a way of how to add comments to Sharepoint site using REST API. It is explained here https://beaucameron.com/2021/01/18/add-comments-to-sharepoint-list-items-using-the-rest-api/ for example.
But when I add comment like this, it adds it on behalf of my name - because REST endpoint is accessed using access token, which is linked to my e-mail.
I'd like to migrate comments from one site to the other, and keep original authors.
Is there a way to post comments on behalf of other users?
I tried this POST body:
{
"__metadata": {
"type": "Microsoft.SharePoint.Comments.comment"
},
"text": "Some new comment",
"author": {
"__metadata": {
"type": "SP.Sharing.Principal"
},
"email": "AlexW#OnMicrosoft.com",
"id": 18,
"loginName": "i:0#.f|membership|alexw#onmicrosoft.com",
"name": "Alex Wilber",
"principalType": 1
}
}
But still, comment is posted on behalf of my name. The response is like the following:
{
"d": {
"__metadata": {
"id": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)",
"uri": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)",
"type": "Microsoft.SharePoint.Comments.comment"
},
"likedBy": {
"__deferred": {
"uri": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)/likedBy"
}
},
"replies": {
"__deferred": {
"uri": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)/replies"
}
},
"author": {
"__metadata": {
"type": "SP.Sharing.Principal"
},
"email": "myName.mySurname#onmicrosoft.com",
"expiration": null,
"id": 12,
"isActive": true,
"isExternal": false,
"jobTitle": null,
"loginName": "i:0#.f|membership|myName.mySurname#onmicrosoft.com",
"name": "myName mySurname",
"principalType": 1,
"userId": null,
"userPrincipalName": null
},
"createdDate": "2022-05-24T08:40:19.0841947Z",
"id": "15",
"isLikedByUser": false,
"isReply": false,
"itemId": 1,
"likeCount": 0,
"listId": "017dd808-5a37-4d65-89f9-b5ce994554b4",
"mentions": null,
"parentId": "0",
"replyCount": 0,
"text": "Some new comment"
}
}
So still, I'm the author of the comment...
Is it possible through the Github API to tell if a commit is a merge commit? And which branch it was merged from?
I am trying to look at all the files changed when comparing two commits on a branch, but I want to ignore any changes done by merge commits from the branch that it's branched from. Any branches that have branched off the branch will not have their merge commits ignored.
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/commits
You can use this API to fetch all the commits. After fetching all the commits the response would look like this as per GitHub's API documentation.
[
{
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
"node_id": "MDY6Q29tbWl0NmRjYjA5YjViNTc4NzVmMzM0ZjYxYWViZWQ2OTVlMmU0MTkzZGI1ZQ==",
"html_url": "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"comments_url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e/comments",
"commit": {
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"author": {
"name": "Monalisa Octocat",
"email": "support#github.com",
"date": "2011-04-14T16:00:49Z"
},
"committer": {
"name": "Monalisa Octocat",
"email": "support#github.com",
"date": "2011-04-14T16:00:49Z"
},
"message": "Fix all the bugs",
"tree": {
"url": "https://api.github.com/repos/octocat/Hello-World/tree/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
},
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"author": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e"
}
]
}
]
In the above payload, for each item in the array, if you have multiple lines in the "parents" key, then it means it is a merge commit. The above payload example has only one line in the "parents" array, so it is not a merge commit.
To find out which branch it was merged from, I believe there is currently no solution using the Github API.
I was searching through the api docs. It appear the same api call is being used for getting details except content when a dir is provided and content when a single file is given.
https://docs.github.com/en/rest/reference/repos#get-repository-content--code-samples
In the case of Response if content is a file
"type": "file",
"encoding": "base64",
"size": 5362,
"name": "README.md",
"path": "README.md",
"content": "encoded content ...",
"sha": "3d21ec53a331a6f037a91c368710b99387d012c1",
"url": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
"git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
"html_url": "https://github.com/octokit/octokit.rb/blob/master/README.md",
"download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/README.md",
"_links": {
"git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1",
"self": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md",
"html": "https://github.com/octokit/octokit.rb/blob/master/README.md"
}
}
In case of Response if content is a directory
{
"type": "file",
"size": 625,
"name": "octokit.rb",
"path": "lib/octokit.rb",
"sha": "fff6fe3a23bf1c8ea0692b4a883af99bee26fd3b",
"url": "https://api.github.com/repos/octokit/octokit.rb/contents/lib/octokit.rb",
"git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/fff6fe3a23bf1c8ea0692b4a883af99bee26fd3b",
"html_url": "https://github.com/octokit/octokit.rb/blob/master/lib/octokit.rb",
"download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/lib/octokit.rb",
"_links": {
"self": "https://api.github.com/repos/octokit/octokit.rb/contents/lib/octokit.rb",
"git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/fff6fe3a23bf1c8ea0692b4a883af99bee26fd3b",
"html": "https://github.com/octokit/octokit.rb/blob/master/lib/octokit.rb"
}
},
{
"type": "dir",
"size": 0,
"name": "octokit",
"path": "lib/octokit",
"sha": "a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d",
"url": "https://api.github.com/repos/octokit/octokit.rb/contents/lib/octokit",
"git_url": "https://api.github.com/repos/octokit/octokit.rb/git/trees/a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d",
"html_url": "https://github.com/octokit/octokit.rb/tree/master/lib/octokit",
"download_url": null,
"_links": {
"self": "https://api.github.com/repos/octokit/octokit.rb/contents/lib/octokit",
"git": "https://api.github.com/repos/octokit/octokit.rb/git/trees/a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d",
"html": "https://github.com/octokit/octokit.rb/tree/master/lib/octokit"
}
}
]
How can I get the content too as an output field for all the files in a directory through a single api call. Is there any way to do so?
I'm currently using GitHub as a scm. I'm currently building a tool around it but came across some issues. Is there any way to check the pull request assignees and who approved the pull request?
In bitbucket it is really easy to do so, but using GitHub I do not see where to do it :/
You can get a pull request's assignee by using our Issues API:
https://developer.github.com/v3/issues
Specifically, this endpoint:
https://developer.github.com/v3/issues/#get-a-single-issue
Since the Multiple Assignees API is still in preview mode, you will need to explicitly pass this custom media type in the Accept Header:
application/vnd.github.cerberus-preview+json
Omitting this header from the request will not show the multiple assignees for an Issue or Pull Request.
curl https://api.github.com/repos/angular/angular/issues/9355 \
-H "Accept: application/vnd.github.cerberus-preview+json" \
The payload should look something like this, including both assignees
{
"url": "https://api.github.com/repos/angular/angular/issues/9355",
"repository_url": "https://api.github.com/repos/angular/angular",
"labels_url": "https://api.github.com/repos/angular/angular/issues/9355/labels{/name}",
"comments_url": "https://api.github.com/repos/angular/angular/issues/9355/comments",
"events_url": "https://api.github.com/repos/angular/angular/issues/9355/events",
"html_url": "https://github.com/angular/angular/pull/9355",
"id": 161102291,
"number": 9355,
"title": "fix(HTTP/XhrBackend): correctly set the status code on errors",
"user": {
"login": "vicb",
"id": 248818,
"avatar_url": "https://avatars.githubusercontent.com/u/248818?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/vicb",
"html_url": "https://github.com/vicb",
"followers_url": "https://api.github.com/users/vicb/followers",
"following_url": "https://api.github.com/users/vicb/following{/other_user}",
"gists_url": "https://api.github.com/users/vicb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/vicb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/vicb/subscriptions",
"organizations_url": "https://api.github.com/users/vicb/orgs",
"repos_url": "https://api.github.com/users/vicb/repos",
"events_url": "https://api.github.com/users/vicb/events{/privacy}",
"received_events_url": "https://api.github.com/users/vicb/received_events",
"type": "User",
"site_admin": false
},
"labels": [
{
"url": "https://api.github.com/repos/angular/angular/labels/cla:%20yes",
"name": "cla: yes",
"color": "009800"
},
{
"url": "https://api.github.com/repos/angular/angular/labels/comp:%20http",
"name": "comp: http",
"color": "c7def8"
},
{
"url": "https://api.github.com/repos/angular/angular/labels/pr_action:%20review",
"name": "pr_action: review",
"color": "fbca04"
},
{
"url": "https://api.github.com/repos/angular/angular/labels/type:%20bug",
"name": "type: bug",
"color": "EEEEEE"
}
],
"state": "open",
"locked": false,
"assignee": {
"login": "jeffbcross",
"id": 463703,
"avatar_url": "https://avatars.githubusercontent.com/u/463703?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/jeffbcross",
"html_url": "https://github.com/jeffbcross",
"followers_url": "https://api.github.com/users/jeffbcross/followers",
"following_url": "https://api.github.com/users/jeffbcross/following{/other_user}",
"gists_url": "https://api.github.com/users/jeffbcross/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jeffbcross/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jeffbcross/subscriptions",
"organizations_url": "https://api.github.com/users/jeffbcross/orgs",
"repos_url": "https://api.github.com/users/jeffbcross/repos",
"events_url": "https://api.github.com/users/jeffbcross/events{/privacy}",
"received_events_url": "https://api.github.com/users/jeffbcross/received_events",
"type": "User",
"site_admin": false
},
"milestone": {
"url": "https://api.github.com/repos/angular/angular/milestones/62",
"html_url": "https://github.com/angular/angular/milestones/2.0.0-rc.3",
"labels_url": "https://api.github.com/repos/angular/angular/milestones/62/labels",
"id": 1831054,
"number": 62,
"title": "2.0.0-rc.3",
"description": "",
"creator": {
"login": "IgorMinar",
"id": 216296,
"avatar_url": "https://avatars.githubusercontent.com/u/216296?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/IgorMinar",
"html_url": "https://github.com/IgorMinar",
"followers_url": "https://api.github.com/users/IgorMinar/followers",
"following_url": "https://api.github.com/users/IgorMinar/following{/other_user}",
"gists_url": "https://api.github.com/users/IgorMinar/gists{/gist_id}",
"starred_url": "https://api.github.com/users/IgorMinar/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/IgorMinar/subscriptions",
"organizations_url": "https://api.github.com/users/IgorMinar/orgs",
"repos_url": "https://api.github.com/users/IgorMinar/repos",
"events_url": "https://api.github.com/users/IgorMinar/events{/privacy}",
"received_events_url": "https://api.github.com/users/IgorMinar/received_events",
"type": "User",
"site_admin": false
},
"open_issues": 25,
"closed_issues": 14,
"state": "open",
"created_at": "2016-06-15T23:19:22Z",
"updated_at": "2016-06-20T17:55:29Z",
"due_on": null,
"closed_at": null
},
"comments": 0,
"created_at": "2016-06-20T01:21:21Z",
"updated_at": "2016-06-20T01:21:22Z",
"closed_at": null,
"pull_request": {
"url": "https://api.github.com/repos/angular/angular/pulls/9355",
"html_url": "https://github.com/angular/angular/pull/9355",
"diff_url": "https://github.com/angular/angular/pull/9355.diff",
"patch_url": "https://github.com/angular/angular/pull/9355.patch"
},
"body": "fixes #9329\r\nfixes angular/http#54\r\n\r\n#robwormald #jeffbcross could one of you please review ? Thanks",
"closed_by": null,
"assignees": [
{
"login": "jeffbcross",
"id": 463703,
"avatar_url": "https://avatars.githubusercontent.com/u/463703?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/jeffbcross",
"html_url": "https://github.com/jeffbcross",
"followers_url": "https://api.github.com/users/jeffbcross/followers",
"following_url": "https://api.github.com/users/jeffbcross/following{/other_user}",
"gists_url": "https://api.github.com/users/jeffbcross/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jeffbcross/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jeffbcross/subscriptions",
"organizations_url": "https://api.github.com/users/jeffbcross/orgs",
"repos_url": "https://api.github.com/users/jeffbcross/repos",
"events_url": "https://api.github.com/users/jeffbcross/events{/privacy}",
"received_events_url": "https://api.github.com/users/jeffbcross/received_events",
"type": "User",
"site_admin": false
},
{
"login": "robwormald",
"id": 534930,
"avatar_url": "https://avatars.githubusercontent.com/u/534930?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/robwormald",
"html_url": "https://github.com/robwormald",
"followers_url": "https://api.github.com/users/robwormald/followers",
"following_url": "https://api.github.com/users/robwormald/following{/other_user}",
"gists_url": "https://api.github.com/users/robwormald/gists{/gist_id}",
"starred_url": "https://api.github.com/users/robwormald/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/robwormald/subscriptions",
"organizations_url": "https://api.github.com/users/robwormald/orgs",
"repos_url": "https://api.github.com/users/robwormald/repos",
"events_url": "https://api.github.com/users/robwormald/events{/privacy}",
"received_events_url": "https://api.github.com/users/robwormald/received_events",
"type": "User",
"site_admin": false
}
]
}
From file,
====================================
{
"id": "ffc131ff-1793-4109-940f-5b537f7061cf",
"securityResourceId": "48d0eeff-690d-4c2c-b6f9-9b25315f9ca3",
"name": "Dev-bpimdmgr-idev3-01",
"active": true,
"licensed": true,
"licenseType": "AUTHORIZED",
"status": "ONLINE",
"tags": []
},
{
"id": "82db2888-7a2f-48fe-bc25-26a5e28bb340",
"securityResourceId": "5a437865-6ced-402e-ac47-dd38191e5696",
"name": "obiee-cmixdmgr-nprd3-01",
"active": true,
"licensed": true,
"licenseType": "AUTHORIZED",
"status": "ONLINE",
"tags": [
{
"id": "fbf62944-a8a4-4a22-8e75-cd8d88eacaff",
"name": "obiee-tag",
"color": "#32cd32",
"description": "obiee tag for version import",
"objectType": "Agent"
}
]
},
I want to delete tags[] block including where are there inside this block. through perl or shell script
Regards,
Kalaiyarasan
Just use the JSON module:
use JSON qw{ from_json to_json };
my $struct = from_json("[$input]");
delete $_->{tags} for #$struct;
print to_json($struct);