DEV Community

Rin
Rin

Posted on • Edited on

1 1

Removes the specified Collaborators from all repositories of the target Gituhub account.

Removes the specified Collaborators from all repositories of the target Gituhub account.

Please check this Github for details.

Overall picture


 /**
     * GLOBAL
     * gitアカウントのメールアドレス
     * ログインパスワード
     * githubのアカウント名
     * 削除したいユーザー
     * を入力してください。
     */
    $Email = '';
    $PASS = '';
    $USER = '';
    $DELTE_USER = '';


    /**
     * 下記のAPIを実行し、api.jsonを作成してください。別途アクセストークンが必要です。
     * curl  "https://api.github.com/user/repos?access_token={token}&per_page=100&page=1&sort=created" > api.json
     */

    $url = './api.json';
    $json = file_get_contents($url);
    $json = mb_convert_encoding($json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN');
    $arr = json_decode($json,true);
    echo $count = count($arr);


    for ($i = 0; $i < $count; ++$i) {
        $repoName = $arr[$i]['name'];

        $cmd = "curl -X DELETE -u $Email:$PASS 'https://api.github.com/repos/$USER/$repoName/collaborators/$DELTE_USER'";
        echo $repoName;
        echo exec($cmd);
    }

Enter fullscreen mode Exit fullscreen mode

First, please get APIKey from setting of Github management screen.
In that case, please check the repo of Select scopes.

After obtaining the access token, execute the following command to create api.json.

curl  "https://api.github.com/user/repos?access_token={token}&per_page=100&page=1&sort=created" > api.json
Enter fullscreen mode Exit fullscreen mode

Specify a variable of remove.php.

$Email = 'hoge@gmail.com';
$PASS = 'password';
$USER = 'MyName';
$DELTE_USER = 'user_id';
Enter fullscreen mode Exit fullscreen mode

Run remove.php

php remove.php
Enter fullscreen mode Exit fullscreen mode

Supplement

A maximum of 100 repositories can be acquired.
If you want to get more than 100 repositories, create additional json file separately as below,
Run PHP again specifying the file.

curl  "https://api.github.com/user/repos?access_token={token}&per_page=100&page=2&sort=created" > api_2.json
Enter fullscreen mode Exit fullscreen mode

remove.php

$url = './api_2.json';
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay