Git Product home page Git Product logo

github-bulk-editor's Introduction

github-bulk-editor

I needed to transfer a large bunch of repositories from one organization to another one. I had already found https://github.com/ahmadnassri/github-bulk-transfer, but that looked quite brittle, and I am honestly not a big fan of node.js projects anyway (cough left-pad cough).

So I put this tool together over the course of a couple of evenings, which allows you to:

  • fetch a list of items from the Github API - currently supported:
    • all repos the current user has permission for
    • all teams in an organization
    • all members of an organization
  • and execute an API command for a selected subset of the items - currently supported:
    • transfer repos to another organization
    • remove teams
    • remove members

Screenshot

To use it, you need to add your own account and access token from https://github.com/settings/tokens in line 10 (https://github.com/floe/github-bulk-editor/blob/master/github-bulk-editor.py#L10).

Currently, the only well-tested actions are a) fetching a list of repos you have access to, and b) transferring those repos to another user/org, because that is the functionality I needed right now.

However, I've tried to keep the internals as generic as possible (see https://github.com/floe/github-bulk-editor/blob/master/github-bulk-editor.py#L14-L27):

# command title: [ GET url, JSON field to extract from result ]
fetch_cmds = { 
    "Get all repositories": [ "https://api.github.com/user/repos", "full_name"],
    "Get all teams": [ "https://api.github.com/orgs/mmbuw/teams", "slug" ], # TODO: make org name editable
    "Get all members": [ "https://api.github.com/orgs/mmbuw/members", "login" ], # TODO: make org name editable
}

# command title: [ request function, url, parameters ] (will be passed through format(name,id), hence the double braces)
action_cmds = {
    "Transfer repository": [ "github_post", "https://api.github.com/repos/{0}/transfer", '{{ "new_owner": "{0}", "team_ids": [] }}' ],
    "Delete team": [ "github_delete", "https://api.github.com/teams/{1}", "" ],
    "Remove member": [ "github_delete", "https://api.github.com/orgs/mmbuw/members/{0}", "" ], # TODO: fixed org name
}

# ...

# post a payload to url
def github_post(url,payload):
    r = requests.post(url,auth=cred,headers=headers,data=payload,allow_redirects=True)
    return r

In theory, you should be able to just add new entries to fetch_cmds and action_cmds to support new API calls, and perhaps add something like another github_put (or whatever) function.

P.S. If you're wondering why I used requests + json (as also suggested at https://stackoverflow.com/a/10626326/838719) instead of PyGithub or similar, none of the existing Python libraries actually support the "Transfer Repo" command. Duh.

github-bulk-editor's People

Contributors

floe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

github-bulk-editor's Issues

Error while selecting "Get all repositories" option

Hi ,

I tried to use the tool created by you by referring to your read.md (as I am working on the same task as you to transfer repo from one org to another) . When I executed script by supplying my account details (login and password at line 10) , I am getting below error. Is there any changes in this code that I should be aware of to use it?

python3 github-bulk-editor.py
Get all repositories https://api.github.com/user/repos full_name
Traceback (most recent call last):
File "github-bulk-editor.py", line 138, in on_source_activate
self.liststore.append([False,"",item[field],item["id"]])
TypeError: string indices must be integers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.