Use the Bitbucket API to collect and back up repository information.
The main purpose is to deal with repository deletion due to Mercurial decommissioning, but it also supports Git repositories.
Initially, the abolition of Mercurial was due on May 31, 2020, but due to the situation, it was postponed for one month.
This article does not cover the topic of repository migration. Please refer to the following articles.
API
Information such as the Bitbucket repository can be obtained with the API.
I referred to the following article.
I wrote a script for collecting information in Python.
Please rewrite the user name and password to get the information of the private repository.
3rd line
authinfo = "USER:PASS"
When you run the script, the API collects repository and snippet information. Combines information divided into multiple pages into one file. (Shaped)
Information such as issues and pull requests is saved in a directory for each repository. (Unshaped)
Repositories and snippets are not cloned automatically. Execute the shell script for the output clone.
We put weight on access.
Line 19
time.sleep(1)
Put the saved JSON in the cache directory and refer to it when you execute it again. If you want to get it again, delete it.
Save the JSON in the cache as it is sent. There are no line breaks, so it's a good idea to format it when reading.
Plastic surgery example
python -m json.tool cache/repositories-1.json
Get the information in the links that references the API.
"links": {
"watchers": {
"href": "https://api.bitbucket.org/2.0/(Omitted)"
},
"branches": {
"href": "https://api.bitbucket.org/2.0/(Omitted)"
},
"tags": {
"href": "https://api.bitbucket.org/2.0/(Omitted)"
},
"commits": {
"href": "https://api.bitbucket.org/2.0/(Omitted)"
},
(Omitted)
},
The source code of json.tool can be used as an example of creating a simple command using the functions of the library.