Skip to content

Commit

Permalink
Get org members
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 13, 2019
1 parent 0eefc41 commit 3208398
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Netkan/Sources/Github/GithubApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ public IEnumerable<GithubRelease> GetAllReleases(GithubRef reference)
}
}
}

public List<GithubUser> getOrgMembers(GithubUser organization)
{
return JsonConvert.DeserializeObject<List<GithubUser>>(
Call($"orgs/{organization.Login}/public_members")
);
}

private string Call(string path)
{
Expand Down
1 change: 1 addition & 0 deletions Netkan/Sources/Github/IGithubApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ internal interface IGithubApi
GithubRepo GetRepo(GithubRef reference);
GithubRelease GetLatestRelease(GithubRef reference);
IEnumerable<GithubRelease> GetAllReleases(GithubRef reference);
List<GithubUser> getOrgMembers(GithubUser organization);
}
}
20 changes: 15 additions & 5 deletions Netkan/Transformers/GithubTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,21 @@ private JToken getAuthors(GithubRepo repo, GithubRelease release)
var authors = new List<string>() { release.Author };
for (GithubRepo r = repo; r != null;)
{
if (r.Owner?.Login != null
&& r.Owner?.Type == userType
&& !authors.Contains(r.Owner.Login))
switch (r.Owner.Type)
{
// Prepend repo owner
authors.Insert(0, r.Owner.Login);
case userType:
// Prepend repo owner
if (!authors.Contains(r.Owner.Login))
authors.Insert(0, r.Owner.Login);
break;
case orgType:
// Prepend org members
authors.InsertRange(0,
_api.getOrgMembers(r.Owner)
.Where(u => !authors.Contains(u.Login))
.Select(u => u.Login)
);
break;
}
// Check parent repos
r = r.ParentRepo == null
Expand All @@ -167,5 +176,6 @@ private JToken getAuthors(GithubRepo repo, GithubRelease release)
}

private const string userType = "User";
private const string orgType = "Organization";
}
}

0 comments on commit 3208398

Please sign in to comment.