I have bunch of repository forks, and I would like to enable all their issue trackers. I am not sure why, GitHub comes with them disabled by default and I had forgot to enable them when forking.
Now would be too much work enable their issues tracker one by one, then, I though I could write a program to do this. For now, I managef to get a list of all repositories I own, with the following code:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import os
import shlex
import json
import subprocess
current_directory = os.path.dirname( os.path.realpath(__file__) )
print( 'directory walk %s', current_directory )
token = "Authorization: token mynicetoken102312312541230240021470300250230"
user_name = "myusername"
def run_command(absolute_path, command_name):
command = shlex.split( command_name )
print( 'command: %s' % command )
command_line_interface = subprocess.Popen( command, stdout=subprocess.PIPE, cwd=absolute_path )
output = command_line_interface.communicate()[0]
print( "\n%s" % output.decode('utf-8') )
return output
def main():
result = run_command( current_directory, "curl -H '%s' https://api.github.com/users/%s/repos" % ( token, user_name ) )
result_json = json.loads( result.decode('utf-8') )
for repository_data in result_json:
repository_full_name = repository_data['full_name']
print( "Processing{:s}".format( repository_full_name ) )
# Now, what do?
run_command( current_directory, "curl -H '%s' https://api.github.com/%s/misterX" % ( token, repository_full_name ) )
if __name__ == "__main__": main()
I think the only thing missing is the complete the last line:
# Now, what do?
run_command( current_directory, "curl -H '%s' https://api.github.com/%s/misterX" % ( token, repository_full_name ) )
After finding How do I rename a GitHub repository via their API? I manage to build the following code:
# Now, what do?
full_command = \
r"""
curl
-H "Authorization: Token %s"
-H "Content-Type: application/json"
-H "Accept: application/json"
-X PATCH
--data '{ "has_issues": true }'
https://api.github.com/repos/:%s
""" % ( token, repository_full_name )
print( 'full_command: %s' % full_command )
run_command( current_directory, full_command )
But GitHub says:
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/repos/#edit"
}
Their API page does not help much: https://developer.github.com/v3/repos/#edit
References:
- How to retrieve the list of all github repositories of a person?
- https://github.com/settings/tokens GitHub token with full repository access