Custom location text for GitHub organization - github

How do I set a custom text for the location field of my GitHub organization? Such as the one below:
Under the settings of the organization, I can only find a drop-down menu that lets me select a country.

A little late to the game, but this solved my issue!
For organizations:
curl -H "Authorization: bearer GH_PAT_HERE" -d '{"location":"YOUR CUSTOM LOCATION"}' https://api.github.com/orgs/ORG_NAME
Additionally for users:
curl -H "Authorization: bearer GH_PAT_HERE" -d '{"location":"YOUR CUSTOM LOCATION"}' https://api.github.com/user
Credit: https://github.community/t/setting-custom-location-for-github-free-organizations/193506/2

The previous method didn't work for me in 2022, but I found something much simpler.
First, go to your organisation settings.
Next, open DevTools and find the element with ID organization_profile_location. Change its value to whatever you like.
Finally, press "Update profile" to save your changes. Use this method at your own risk, as it is not official.
According to Teddy van Jerry (someone in the comments), this isn't valid for requesting publisher verification.

Related

APIs Explorer's Firestore's projects.databases.documents.list has incorrect regex

Summary: APIs Explorer "Try this API" for projects.databases.documents.list appears (!?) to have an overly restrictive/incorrect regex on parent and requirement on collectionId.
Neither gcloud firestore nor firebase firestore: provides functionality to list collections, I'm planning to write a simple app to do so.
As always, I explored the APIs methods using the excellent APIs Explorer but the projects.databases.documents.list "Try this API" appears (!?) to have an overly restrictive|incorrect regex on parent.
The documentation correctly states that:
https://firestore.googleapis.com/v1/{parent=projects/*/databases/*/documents/*/**}/{collectionId}
And:
Required. The parent resource name. In the format:
projects/{project_id}/databases/{database_id}/documents or
projects/{project_id}/databases/{database_id}/documents/{document_path}.
For example: projects/my-project/databases/my-database/documents or projects/my-project/databases/my-database/documents/chatrooms/my-chatroom
Using Google's first format example: projects/my-project/databases/my-database/documents does not work:
APIs Explorer only accepts the second format example for parent but then requires a value for collectionId which may not be desired:
APIs Explorer appends collectionId to the parent to from the URL. In the case of parent ending /documents (which isn't permitted), this would make sense to access the chatrooms collection or in the case that parent ends /documents/chatrooms/my-chatroom to then get the messages collection (with my-chatroom) but the requirement prohibits using APIs Explorer (!) to query projects/my-project/databases/my-database/documents/chatrooms; collectionId is required and would need to be chatrooms but a parent of projects/my-project/databases/my-database/documents is not permitted.
Using one of my projects (${PROJECT}) and (default) for {database_id}, I can use the documentation's examples correctly in curl:
TOKEN=$(gcloud auth print-access-token)
PROJECT=...
PARENT=projects/${PROJECT}/databases/(default)/documents
COLLECTION=...
curl \
--header "Authorization: Bearer ${TOKEN}" \
--header 'Accept: application/json' \
--write-out '%{response_code}' \
--output /dev/null \
--silent \
https://firestore.googleapis.com/v1/${PARENT}/${COLLECTION}
200
The APIs works correctly navigating down through subcollections too.
Posting this here in the hopes that, if APIs Explorer is indeed incorrect, fixing it can help other developers not encounter this issue and be discouraged.
Note: Since I'm posting feedback, the tool doesn't correctly adjust cURL, HTTP or JavaScript generated examples to reflect the checkbox value on "API Key"; when the "API Key" is deselected, the parameter should not be included in the calls.
It seems to be a problem with the regular expression in the API explorer. I need to enter the parent as projects/fire-template-24/databases/(default)/documents/users/ (including the forward slash) and also enter the collectionId as it's required (users in my case). This seems to be making a query at:
https://[GOOGLE+APIS_URL]/projects/[ID]/databases/(default)/documents/users//users?key=[API_KEY]
This returns an error about the extra trailing slash which the API explorer forced me to add and collectionId field is also appended to it with another /.
The following regular expression seems to be working:
^projects\/[^/]+\/databases\/[^/]+\/documents(\/[^/]+(\/[^/]+\/[^/]+)*)$
The above RegEx doesn't required a forward slash in parent and matches a collection path only. If the collectionId is removed then it should work. Working example of the RegEx can be found here.
I could also observe the same in the API explorer page. I observed that there is an existing issue in the Public Issue Tracker for the same. As mentioned in the #2 comment of the issue, this issue report has been forwarded to the Firestore Engineering team to investigate, but there is no ETA for a resolution. I would suggest you star the issue so that you will get notified whenever there is any update on the issue.

Delete multiple issue/PR comments via the GitHub API

I want to delete multiple PRs/issues comments at once with GitHub Actions over the GitHub API.
Is there a way to do this without showing the delete message multiple times like the following image?
For example, I thought there may be a way to delete multiple issue/pull request review comments with one request that shows a message like <user> deleted n comments from <users whose comments have been deleted>?
Currently, I am deleting messages using the following curl command in a loop:
echo "$ids" | while read -r id; do
curl -X "DELETE" -s -H "authorization: token $GITHUB_TOKEN" -H "User-Agent: Actions-<username>/<reponame>" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/<username>/<reponame>/issues/<issue number>/comments/$id"
done
If it is a pull request, I use pulls with instead of issues.
I also think that there is a rate limit preventing the deletion of that many commands in such a short time.
See the docs for deleting an issue and a pull request comment.
[Context]
I want to create a command that clears multiple messages at once. If somebody enters /clear 5 for example, the latest 5 messages will be deleted.
No, you can't do it. It is a core feature from Github to create a timeline event on any action (like push, comment, rebase, merge, etc). That's a standard placeholder.
https://help.github.com/en/github/building-a-strong-community/managing-disruptive-comments#deleting-a-comment
Also, it looks like Github doesn't support BATCH operations currently.
So, NO and NO at the moment :(

Is it possible to copy sheets over for new budget year, including outbound links?

I have about 75 sheets I have created for our 2019 fiscal year that list budget and actual values for certain company expenses, which link out to a few different summary sheets based on region. I wanted to copy all sheets and blank them out to roll out for the 2020 fiscal year. When I use the Smartsheet API to copy a sheet, it only allows me to copy over inbound links, not outbound ones. Is there a way to copy over outbound links, even to a new sheet?
For reference, I ran the copy sheet code located on the Smartsheet API github page:
curl https://api.smartsheet.com/2.0/sheets/[sheet ID]/copy?include=data,attachments,cellLinks
-H "Authorization: Bearer [token]"
-H "Content-Type: application/json"
-d '{
"destinationType": "home",
"destinationId": null,
"newName": "newSheetName"
}'
-X POST
At this time when making a copy of a sheet, via the API or the UI in your browser, it will only save the inbound cell links. Outbound cell links will be removed with the cell data remaining in place in the newly created sheet. There currently isn't a method to keep the cell links in place via the copy. They would need to be recreated after the copy is done.

How to search for code in GitHub with GitHub API?

I'm trying to search for some piece of code using the GitHub API V3 given only the keyword, not limiting by user, organization, or repository.
For example, if I want to search for all pieces of code that contain the keyword "addClass", the results would be
https://github.com/search?q=addClass&type=Code&ref=searchresults without using GitHub API.
But how can I do the same thing through GitHub API? I tried https://api.github.com/search/code?q=addClass
It says "Must include at least one user, organization, or repository". How can I fix this?
You can do a code search without specifying a user/org/repo if you authenticate.
First, generate a personal access token for use for this purpose, from your Profile on GitHub's website:
Settings -> Developer Settings -> Personal Access Token -> Generate New Token (you can leave all access options unticked, since you're just using to make web requests)
Now, your original GET request will work and return results, if you append the token to it:
https://api.github.com/search/code?q=addClass&access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
UPDATE: OCT 2021
As pointed out by a comment below, passing the token in via a query parameter (like above) is deprecated. You must now add it as an Authorization header.
e.g.
curl --location --request GET 'https://api.github.com/search/code?q=addClass +in:file +language:csharp' \
--header 'Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
or in Python:
import requests
url = "https://api.github.com/search/code?q=addClass +in:file +language:csharp"
headers = {
'Authorization': 'Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
response = requests.request("GET", url, headers=headers)
print(response.text)
2020: As detailed in Mark Z.'s answer, using an authentication (Authorization': 'Token xxxx') allows for a code search.
get /search/code
You can use:
either a dedicated command-line tool like feinoujc/gh-search-cli
ghs code --extension js "import _ from 'lodash'"
or the official GitHub CLI gh, (after a gh auth login) as show in issue 5117:
gh api --method=GET "search/code?q=filename:test+extension:yaml+org:new-org"
Or even:
gh api --method=GET search/code -f q='filename:test extension:yaml org:new-org' \
--jq '.items[] | [.repository.full_name,.path,.sha] | #tsv'
That would get a line-based, tab-separated list of fields in this order: repo name, file path, git sha. (see gh help formatting)
2014 (original answer): That seems related to the new restriction "New Validation Rule for Beta Code Search API" (Oct. 2013)
In order to support the expected volume of requests, we’re applying a new validation rule to the Code Search API. Starting today, you will need to scope your code queries to a specific set of users, organizations, or repositories.
So, the example of the API search code mentions now:
Suppose you want to find the definition of the addClass function inside jQuery. Your query would look something like this:
https://api.github.com/search/code?q=addClass+in:file+language:js+repo:jquery/jquery
While Gihub does not currently support code search without repo, user, or organization (see VonC's answer), codesearch does index some sources from Github via the codesearch API, albeit with an API less fully featured out than Github's.
For example, to search for wget invocations indexed from Github, call
curl "https://searchcode.com/api/codesearch_I/?q=wget&src=2"
The optional src parameter picks the code source (e.g., Github, BitBucket) that should be searched, and you can find its integer value for a source by altering the parameters of faceted search in the codesearch UI. The current value of src for Github is 2.
You can verify that the returned results from the above example come from github.com by viewing the the repo property of results items.

How can I post in Facebook wall programmatically?

I'm very new to Facebook (yeah, I'm the only one) but I'd like to publish messages in the wall programmatically using Python.
What do I need to do to achieve that? I'm very confused. I have seen that most question about this are focused on how to let an app interact in some way with Facebook, but I'd like to post as if I were a simple user (a user which happens to "own" that particular Facebook page). Do I really need to go and create an app? (By the way, I'm having problems even with that... it tells me that my account seems fake or invalid even after I validated it via SMS). I imagine that there is a simpler way, introducing my credentials, using a POST request but I haven't read something similar.
I would have thought this is what I needed, but it leads to a page to create an app.
Some pointers?
By the way, I got a token via a publish_stream permission in the Graph API Explorer (using the extended permissions tab). Seems like this permission doesn't have expiration date but it's not recommended. Is there a better choice for a token?.
Thanks
Facebook is a bit trickier than other sites it would appear.
While watching the POST tab under NET in Firebug, while logging in, I see the following POST parameters:
charset_test €,´,€,´,水,Д,Є
default_persistent 1
email myusername
lgnjs 1340241652
lgnrnd 182050_CuPx
locale en_US
lsd AVqwALVx
pass mypassword
persistent 1
timezone 240
I don't yet know what lsd paramater is, but I did find out what the lgnrnd was by viewing the source of the login page before I logged in. It appears to be there to make it more difficult to automate authentication.
You first want your script to scrape that login page for that value, store it in a variable. Then, a cURL example would be something like:
curl -L "https://www.facebook.com/login.php?login_attempt=1" \
--cookie-jar /tmp/cookies.txt \
--data-urlencode "email=myusername" \
--data-urlencode "lgnrnd=$lgnrnd" \
--data-urlencode "pass=mypassword"
and so forth, with all the parameters...
This is untested of course, and I don't know what some of those parameter values are yet, but you should get the idea from that. You could probably use a python module like Beautiful Soup or something to apply the above basic concept.
Then you would do the same thing, watching the NET tab to find the parameters sent when you post to your facebook wall, and put it all together.
Note that I'm storing and using cookies with curl's --cookie-jar option. You will need a way to save and use cookies with the request as well, which is why I showed that.
Hope that helps you get started anyway..
What about this?.
import urllib2, urllib
parameters = {}
parameters['access_token'] = MY_TOKEN
parameters['message'] = 'Hello world'
target = 'https://graph.facebook.com/MY_ID/feed'
parameters = urllib.urlencode(parameters)
handler = urllib2.urlopen(target, parameters)
while True:
if handler.code < 400:
print handler.read() # Gets post_id
break
elif handler.code >= 400:
print 'Error' # :-(
break
Are there problems with this? Maybe a better way? Comments?
Thanks