Get attachment from issue comment #37639
Replies: 3 comments
-
Hi there @giorgio1980 and welcome to our community! Thank you for asking a great question 🙂 To get started, introduce yourself in our official introduction thread |
Beta Was this translation helpful? Give feedback.
-
There is no handy way to do it via the GraphQL API (or it is well hidden). Alternative:You could try:
Example.QUERY_1Lets get the attachment from this comment made by {
repository(owner: "cli", name: "cli") {
issue(number: 3089) {
comments(first: 100) {
nodes {
author{login}
id
}
}
}
}
} RESULT_1{
"data": {
"repository": {
"issue": {
"comments": {
"nodes": [
{
"author": {
"login": "mislav"
},
"id": "MDEyOklzc3VlQ29tbWVudDc5MTUyMTc0NQ=="
},
{
"author": {
"login": "karlb"
},
"id": "MDEyOklzc3VlQ29tbWVudDc5MTYyNTQzMw=="
},
{
"author": {
"login": "karlb"
},
"id": "MDEyOklzc3VlQ29tbWVudDgwMTgwMzQyNA=="
},
{
"author": {
"login": "mislav"
},
"id": "MDEyOklzc3VlQ29tbWVudDgwMTk0NzYyNQ=="
},
{
"author": {
"login": "mislav"
},
"id": "MDEyOklzc3VlQ29tbWVudDgwMTk1NDQ3MQ=="
},
{
"author": {
"login": "karlb"
},
"id": "MDEyOklzc3VlQ29tbWVudDgwMjAyMTk2NA=="
},
{
"author": {
"login": "mislav"
},
"id": "MDEyOklzc3VlQ29tbWVudDgwMjAyMjkxNw=="
},
{
"author": {
"login": "karlb"
},
"id": "MDEyOklzc3VlQ29tbWVudDgwMjAyNTM3OA=="
},
{
"author": {
"login": "cristiand391"
},
"id": "MDEyOklzc3VlQ29tbWVudDgwMjMxNDEzOA=="
},
{
"author": {
"login": "mislav"
},
"id": "MDEyOklzc3VlQ29tbWVudDgwMjg2NDIwMg=="
},
{
"author": {
"login": "ayushnix"
},
"id": "IC_kwDODKw3uc4-aI0y"
},
{
"author": {
"login": "mislav"
},
"id": "IC_kwDODKw3uc4-aebC"
},
{
"author": {
"login": "ayushnix"
},
"id": "IC_kwDODKw3uc4-afUI"
}
]
}
}
}
}
} QUERY_2Get the query ($id: ID!) {
node(id: $id) {
... on IssueComment {
bodyHTML
}
}
} RESULT_2{
"data": {
"node": {
"bodyHTML": "<p dir=\"auto\">I was able to reproduce this behaviour with Alacritty + <code class=\"notranslate\">clrs-light</code> theme + tmux.</p>\n<p dir=\"auto\"><code class=\"notranslate\">gh issue view 3089 -R cli/cli</code></p>\n<p dir=\"auto\">Left: Alacritty + tmux ----------------------- Right: Alacritty</p>\n<p dir=\"auto\"><a target=\"_blank\" rel=\"noopener noreferrer nofollow\" href=\"https://user-images.githubusercontent.com/6853656/111698152-6340db00-882e-11eb-8f68-85c31c8d044b.png\"><img src=\"https://user-images.githubusercontent.com/6853656/111698152-6340db00-882e-11eb-8f68-85c31c8d044b.png\" alt=\"Screenshot_2021-03-18_18-03-25\" style=\"max-width: 100%;\"></a></p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"alacritty --version\nalacritty 0.6.0-dev (b39c791)\n\ntmux -V\ntmux 2.6\"><pre class=\"notranslate\"><code>alacritty --version\nalacritty 0.6.0-dev (b39c791)\n\ntmux -V\ntmux 2.6\n</code></pre></div>"
}
}
} Extract and download links (using gh, curl and pcregrep)# bash
bodyHTML=$(gh api graphql --field id="MDEyOklzc3VlQ29tbWVudDgwMjMxNDEzOA==" --raw-field query="$QUERY_2" --jq '.data.node.bodyHTML')
LIST_LINKS=()
while IFS='' read -r line; do LIST_LINKS+=("$line"); done < <(pcregrep -o '(?<=src=\")[^"]*' <<<"$bodyHTML")
for link in "${LIST_LINKS[@]}"; do curl "$link" --output "${link/*\//}"; done |
Beta Was this translation helpful? Give feedback.
-
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
-
Hello,
is there a way to get the attachment contained in an issue comment?
The only api I find is related to the files contained in the repository.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions