How to delete my follower at github? - github

Is it possible to do?
If yes, could you please provide a curl example?

Removing a follower on Github in fact is possible with this workaround:
Block the user who watches you, as described in the github help.
Then unblock him again.
After that he will not be blocked anymore and he will also no longer follow you.

Wrote to Github support:
Is there any way to delete followers? I know about "Block User" option but it's not exactly what I want. Github API methods are also suitable.
They answered:
No, this isn't currently possible.
So, there is no way for now. Only "Block User".

Manually: go to user profile - in the right corner there is Follow user and right next to it menu with Block user/Report user.
By clicking on Block user, he was removed from my followers.
Here is Github manual to do that.
Could not find an api alternative.

These would be the curl commands, you were looking for:
Block a user1
$ curl \
-X PUT \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
https://api.github.com/user/blocks/USERNAME
Unblock a user2
$ curl \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
https://api.github.com/user/blocks/USERNAME
1 https://docs.github.com/en/rest/users/blocking#block-a-user
2 https://docs.github.com/en/rest/users/blocking#unblock-a-user

Related

GitHub Actions: Must have admin rights to trigger workflow_dispatch?

Using the github API I am trying to manually start a workflow using:
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: MY_TOKEN" \
https://api.github.com/repos/djpr-data/djprdashdata/actions/workflows/refresh-data.yaml/dispatches
but I keep getting an authentication error:
{
"message": "Must have admin rights to Repository.",
"documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"
}
This seems to be a similar issue to this question. But my PAT token has all admin and repo scopes selected. I also have my user account setup as admin for the repository and I have added a workflow dispatch to the workflow yaml file.
workflow_dispatch:
inputs:
tags:
description:
"run from cmdline"
I have been following the docs at https://docs.github.com/en/rest/actions/workflows#create-a-workflow-dispatch-event and have had no problems using the API to retrieve all previous workflow jobs. I have also tried the runs and jobs endpoints but get the same error. So I am now not sure what else I can do. Is there somewhere else I need to set permissions?
Thanks
This is a poor error message to tell you that your request is not formed correctly. If you want to pass a PAT as a header, you need to prefix it with token, as described in the docs:
-H "Authorization: token MY_TOKEN"
Once that's resolved, however, you'll also get an error because you don't pass the required ref payload. Assuming your default branch is main, here's a correct curl command:
> export MY_TOKEN=gha_abcdef
> curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token $MY_TOKEN" \
-d '{"ref": "main"}' \
https://api.github.com/repos/djpr-data/djprdashdata/actions/workflows/refresh-data.yaml/dispatches

How to attach docs and import issue at the same time using GitHub API?

I need to import all bug reports and attachments from my internal system to GitHub Issues.
What GitHub API parameter should I use to attach a document in my curl command?
curl -X "POST" \
-H "Accept: application/vnd.github+json" \
-H "Accept: application/vnd.github.VERSION.html" \
-H "Authorization: token <token>" \
https://api.github.com/repos/BT23/demo-repo/issues \
-d '{
"title":"Create an issue in HTML format",
"body":"<H1>Testing HTML tags</H1><P>Does it work?</P>",
"assignee": "BT23",
"milestone": 1,
"labels":["bug", "functional"]
}'
Thanks
I do not see the word file anywhere in Issues API.
And this thread confirms you cannot attach a file during Issue Creation.
Adding a file to issue or pull request seems to be done manually through drag & drop only.

How to post the comments on GitHub pull request page using curl.exe?

Are there any possibilities to post the comments on Github pull request page using curl.exe?
I have used the below as below mentioned commands, but it's not working, the comments have not posted on the pull request page. Could you suggest a solution for this?
curl -s -H "UserName:Token" -X POST -d '{"body": "My Review comments"}' "https://api.github.com/repos/UserName/my-docs/issues/11/comments"
In your question you mention "pull request" but your in your curl command you are calling the Issues API....I'll try and limit my answer to what you are attempting to do with the command by making a few changes in the POST headers:
curl -X POST \
-H "Authorization: token $TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/UserName/my-docs/issues/11/comments \
-d '{"body":"My Review comments"}'
If you still run into trouble, run CURL with --verbose or -v option to get more information on what may be happening.

how to change/modify title of an issue when you learn more about the issue/underlying issue itself.

I made a generic title while making a github issue. While trying to explain the issue, I discovered some more details underneath which I could add to the title to explain to the developer better.
I tried to change the title but wasn't able to do that, can modify the body of the message but not the title apparently :(
I tried using [github] modify title or modify heading and few other keywords but couldn't find anything in stackoverflow.com
I even re-read https://guides.github.com/features/issues/ just to see if I missed something when I had read it few years ago.
Looking to know.
Update 2021: you can also use the GitHub CLI gh, instead of curl.
2018:
Considering the GitHub API for Issues does include an "edit issue" which does allow for the title to be modified, this should be possible.
Try (using an OAuth token as shown here):
curl -H 'Authorization: Bearer <your OAuth token>' \
-H "Content-Type: application/json-patch+json" \
-H "Accept: application/json" \
-X PATCH \
https://api.github.com/repos/:owner/:repo/issues/:number \
--data '[{ "title": "a new title" }]'
Or:
curl --request PATCH -H "Authorization: token OAUTH-TOKEN" \
https://api.github.com/repos/:owner/:repo/issues/:number \
--data '[{ "title": "a new title" }]'

Post a comment on Github Pull Request via Command Line

Is there a way I can post a comment on a Github Pull Request via the command line? The ideas is that I want Jenkins to post comments on Pull Requests with a summary of the results of a script.
This is absolutely possible with nothing more than curl.
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
https://api.github.com/repos/octocat/hello-world/issues/42/comments \
-d '{"body":"Hello Github!"}'
Read more about the API in use here https://docs.github.com/en/rest/reference/issues#create-an-issue-comment
NOTE: This assumes you have a Personal Access Token stored in an environment variable named GITHUB_TOKEN
It's not possible without third party extensions.
You may be intrested in this: https://github.com/stephencelis/ghi
Sorry I can't help more!
This is a little late, but this sounds like exactly what you are looking for:
gh pr comment 6 --body "Hi from GitHub CLI"
https://cli.github.com/manual/gh_pr_comment
Simply allows you to add comments to a pr from a given pr number.