之前寫過幾篇文章( Github 透過 Octokit.net 操控 Github - 檔案是否存在,刪除檔案,傳檔案上去 、Github 透過 Octokit.net 操控 Github - 取得所有 Repositories)
使用 Octokit.net https://github.com/octokit/octokit.net 去操控 Github ,今天繼續把一些測試的筆記紀錄一下
1. Fork 其他用戶的 Repository ,這裡面目標我是去 fork 我 github 的一個專案 https://github.com/donma/RSAKeyConverter
//這 DONMATEST 可以任意都可以
var client = new GitHubClient(new ProductHeaderValue("DONMATEST"));
//從網站上取得的 personal access token https://github.com/settings/tokens
var tokenAuth = new Credentials(PersonalToken);
client.Credentials = tokenAuth;
//https://github.com/donma/RSAKeyConverter
var res = client.Repository.Forks.Create("donma", "RSAKeyConverter", new NewRepositoryFork()).Result;
2.刪除自己底下的某個 Repository,範例的 Repository 是 RSAKeyConverter
//這 DONMATEST 可以任意都可以
var client = new GitHubClient(new ProductHeaderValue("DONMATEST"));
//從網站上取得的 personal access token https://github.com/settings/tokens
var tokenAuth = new Credentials(PersonalToken);
client.Credentials = tokenAuth;
var res = client.Repository.Delete(GitHubUserName, "RSAKeyConverter");
3.將Repository 設成公開/私人
//這 DONMATEST 可以任意都可以
var client = new GitHubClient(new ProductHeaderValue("DONMATEST"));
//從網站上取得的 personal access token https://github.com/settings/tokens
var tokenAuth = new Credentials(PersonalToken);
client.Credentials = tokenAuth;
//Set for Public ,如果是要設定為 private , Private 就設成 true
//此案例就是將 LAB 這 Repo 設成 public
client.Repository.Edit(GitHubUserName, "LAB", new RepositoryUpdate("LAB") { Private = false });
為何會研究這個,是因為有時候要 fork 一些其他人的repo ,但是因為要整合其他人的修改很麻煩,只好砍掉重新fork比較快,筆記一下給需要的人,或是以後讓自己快速的CP… :P