Skip to content

Instantly share code, notes, and snippets.

@adamralph
Last active November 10, 2017 10:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adamralph/fd89fb4700b6b26b37f49c0912ffa1f3 to your computer and use it in GitHub Desktop.
Save adamralph/fd89fb4700b6b26b37f49c0912ffa1f3 to your computer and use it in GitHub Desktop.
A LINQPad script to search GitHub repos for package usage (and potentially other things)
<Query Kind="Statements">
<NuGetReference>Humanizer</NuGetReference>
<NuGetReference>Octokit</NuGetReference>
<Namespace>Humanizer</Namespace>
<Namespace>Octokit</Namespace>
<Namespace>Octokit.Internal</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
</Query>
// I wrote this script to help me find out where my NuGet packages are being used.
// When prompted for a GitHub password, enter a personal access token. See https://github.com/settings/tokens
// Change these search parameters accordingly.
// The term to search for
var term = "xbehave";
// The file names to search within
var fileNames = new[] { "packages.config", "*.csproj", "*.vbproj", "*.fsproj" };
// A filter to exclude repositories
Func<Repository, bool> excludeRepository = repository =>
new[] { "adamralph", "adamralph-archive", "xbehave" }.Contains(repository.Owner.Login);
// Let the magic begin...
var client = new GitHubClient(
new ProductHeaderValue("adamralph-code-search-by-repo", "1.0.0"),
new InMemoryCredentialStore(new Credentials(Util.GetPassword("GitHub"))));
(await Task.WhenAll((await Task.WhenAll(
fileNames
.Select(fileName => new SearchCodeRequest(term) { FileName = fileName, })
.Select(async request =>
{
await Task.Delay(500); // attempt to avoid abuse detection by the GitHub API
return await client.Search.SearchCode(request);
})))
.SelectMany(result => result.Items)
.GroupBy(item => item.Repository.HtmlUrl)
.Select(group => group.First())
.Select(async item => await client.Repository.Get(item.Repository.Id))))
.Where(repository => !excludeRepository(repository))
.Select(repository => new
{
HtmlUrl = new Hyperlinq(repository.HtmlUrl),
LastPushed = repository.PushedAt.Humanize(),
repository.ForksCount,
repository.SubscribersCount,
repository.StargazersCount,
repository.PushedAt,
})
.OrderByDescending(repository => repository.PushedAt)
.ToList()
.Dump();
HtmlUrl LastPushed ForksCount SubscribersCount StargazersCount PushedAt
https://github.com/scriptcs/scriptcs 17 minutes ago 339 149 1867 10.11.17 09:43:52 +00:00
https://github.com/agartee/Brickweave 2 hours ago 1 1 1 10.11.17 07:12:08 +00:00
https://github.com/KallynGowdy/ReactiveUI.Routing 5 hours ago 1 1 3 10.11.17 04:35:47 +00:00
https://github.com/fredsena/TDD_STUFF 2 days ago 0 1 0 8.11.17 16:04:33 +00:00
https://github.com/Yan-Fedorov/BullsAndCows 2 days ago 0 1 0 7.11.17 18:57:47 +00:00
https://github.com/hlaueriksson/ConductOfCode 7 days ago 3 2 2 2.11.17 17:33:25 +00:00
https://github.com/colored-console/colored-console 15 days ago 11 5 51 25.10.17 13:08:28 +00:00
https://github.com/wiredwiz/FluentGuard 18 days ago 0 1 0 22.10.17 23:45:24 +00:00
https://github.com/thebothead/apache-avro-adla 20 days ago 0 1 0 20.10.17 13:09:00 +00:00
https://github.com/philippdolder/scs_kata one month ago 2 3 0 10.10.17 10:57:59 +00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment