User.Suspended总是在octokit.net中返回false

时间:2016-04-15 16:01:31

标签: github-api octokit.net

我使用以下代码获取所有GitHub Enterprise用户的列表,然后我试图暂停那些不再在AD中的用户。 Suspend函数有效,但User.Suspended属性始终返回false。

var searhRequest = new SearchUsersRequest("type:user&page="+pageNumber+"&page_size=100");
                githubUsers = await client.Search.SearchUsers(searhRequest);   

 client.User.Administration.Suspend(userId);

1 个答案:

答案 0 :(得分:0)

是的,我认为问题在于我们试图将返回值作为用户投射,而最终在幕后进行的调用并不会返回该数据。作为一种解决方法,在我对原始结果进行四舍五入后,我只是调用了获取用户方法来吸引用户。

它可能会做得更好,但这就是我现在所拥有的

Task<SearchUsersResult> task;
List<User> users = new List<User>();
int page = 1;

do
{
  task = github.Search.SearchUsers(new SearchUsersRequest("type:user&repos:>=0") { Page = page, PerPage = 500 });
  task.Wait();

  users.AddRange(task.Result.Items.ToList<User>());
  page++;
}
while (users.Count < task.Result.TotalCount);

// Get all users by login (this calls the api once for every user you have)
var tasks = users.Select(u => github.User.Get(u.Login));

// Get all unsuspended users
var activeUsers = Task.WhenAll<User>(tasks).Result.Where<User>(u => !u.Suspended).ToList();

请注意,在通话结果中,不包含&#34; isSuspended&#34;数据(使用fiddler从我的本地企业实例中提取然后消毒)

{"login":"User1"
"id":45
"avatar_url":"http://github.com/avatars/u/45?"
"gravatar_id":""
"url":"http://github.com/api/v3/users/User1"
"html_url":"http://github.com/User1"
"followers_url":"http://github.com/api/v3/users/User1/followers"
"following_url":"http://github.com/api/v3/users/User1/following{/other_user}"
"gists_url":"http://github.com/api/v3/users/User1/gists{/gist_id}"
"starred_url":"http://github.com/api/v3/users/User1/starred{/owner}{/repo}"
"subscriptions_url":"http://github.com/api/v3/users/User1/subscriptions"
"organizations_url":"http://github.com/api/v3/users/User1/orgs"
"repos_url":"http://github.com/api/v3/users/User1/repos"
"events_url":"http://github.com/api/v3/users/User1/events{/privacy}"
"received_events_url":"http://github.com/api/v3/users/User1/received_events"
"type":"User"
"site_admin":false
"ldap_dn":"CN=User1
OU=CompanyDEVUsers
OU=Users
OU=Company
DC=Company
DC=com"
"score":1.0}