统计 Github 2021 贡献过的开源项目
統(tǒng)計(jì)一下 2021 貢獻(xiàn)過的開源項(xiàng)目
Intro
新的一年的開始了,有很多總結(jié)和回顧還沒有做,今天就盤點(diǎn)一下貢獻(xiàn)過的開源項(xiàng)目吧~
起初想著手動(dòng)地通過 Github Dashboard 來統(tǒng)計(jì)
但是感覺有些麻煩,還得一個(gè)個(gè)地復(fù)制標(biāo)題鏈接等,好麻煩,于是就想是不是可以寫一個(gè)簡(jiǎn)單的小程序通過 Github 的 API 來統(tǒng)計(jì)呢,答案是肯定的,可以參考后面的示例代碼
Contributions
過去一年的貢獻(xiàn)如下,一共提了 81 個(gè) PR 其中有 43 個(gè)是自己維護(hù)的開源項(xiàng)目的 PR,已從下面的 PR 中移除
統(tǒng)計(jì)結(jié)果來自 Github 的 API:https://api.github.com/search/issues?page=1&q=author%3Aweihanli+type%3Apr+is:merged+merged:%3E=2021-01-01
davidfowl/DotNetCodingPatterns
enhancement on Caching singletons sample code https://github.com/davidfowl/DotNetCodingPatterns/pull/11
domaindrivendev/Swashbuckle.AspNetCore
Enhancement for SwaggerUIMiddleware https://github.com/domaindrivendev/Swashbuckle.AspNetCore/pull/2214
dotnet/aspnetcore
Fix http logging log typo https://github.com/dotnet/aspnetcore/pull/36871
Update 10_bug_report.md https://github.com/dotnet/aspnetcore/pull/36922
dotnet/core
Update for .NET 6 release https://github.com/dotnet/core/pull/6892
dotnet/dotnet-monitor
update windows build script https://github.com/dotnet/dotnet-monitor/pull/40
dotnet/format
Remove unnecessary config https://github.com/dotnet/format/pull/1486
dotnet/issue-labeler
use generic host https://github.com/dotnet/issue-labeler/pull/15
dotnet/maui
Update MauiAppBuilder.cs https://github.com/dotnet/maui/pull/3445
dotnet/runtime
Update ConfigurationManager https://github.com/dotnet/runtime/pull/59600
dotnet/sdk
Add self contained short flag https://github.com/dotnet/sdk/pull/19681
Use null-coalescing assignment operator https://github.com/dotnet/sdk/pull/20678
dotnetcore/CAP
make OperateResult._errors readonly https://github.com/dotnetcore/CAP/pull/869
fix typo in comment https://github.com/dotnetcore/CAP/pull/870
Use KeyExistsAsync for exists check https://github.com/dotnetcore/CAP/pull/1004
dotnetcore/FastGithub
Fix build for .NET 6 with the latest SDK and some warning and typo https://github.com/dotnetcore/FastGithub/pull/26
Remove unnecessary config https://github.com/dotnetcore/FastGithub/pull/84
EdiWang/Moonglade
Common.props enhancement https://github.com/EdiWang/Moonglade/pull/566
IEvangelist/blazorators
Github CodeSpaces support https://github.com/IEvangelist/blazorators/pull/3
Refine the generator https://github.com/IEvangelist/blazorators/pull/6
Apply file-scoped namespace style and skip none partial classes https://github.com/IEvangelist/blazorators/pull/7
IEvangelist/pwned-client
Remove IsExternalInit https://github.com/IEvangelist/pwned-client/pull/6
kubernetes-client/csharp
Update TokenFileAuth https://github.com/kubernetes-client/csharp/pull/631
Expose kube config default location https://github.com/kubernetes-client/csharp/pull/635
Makes realFileSystem readonly https://github.com/kubernetes-client/csharp/pull/655
AddRange extension enhancement https://github.com/kubernetes-client/csharp/pull/771
LemonSharp/Admin.FrontEnd
Add Github CI support https://github.com/LemonSharp/Admin.FrontEnd/pull/2
Add dotnet-monitor https://github.com/LemonSharp/Admin.FrontEnd/pull/4
LemonSharp/User
Publish event when user register success https://github.com/LemonSharp/User/pull/1
LemonSharp/VaccinationCore
Implement AppointmentQueries/VaccinationQueries https://github.com/LemonSharp/VaccinationCore/pull/1
LemonSharp/VaccinationSite
Feat/add appointment api https://github.com/LemonSharp/VaccinationSite/pull/1
Add GetSiteInfoById API https://github.com/LemonSharp/VaccinationSite/pull/2
Add dotnet-monitor sidecar https://github.com/LemonSharp/VaccinationSite/pull/3
Enable swagger on production https://github.com/LemonSharp/VaccinationSite/pull/4
microsoft/reverse-proxy
Fix typo https://github.com/microsoft/reverse-proxy/pull/1245
Use WaitAsync https://github.com/microsoft/reverse-proxy/pull/1306
night-moon-studio/NatashaPad
Update to .NET 6 https://github.com/night-moon-studio/NatashaPad/pull/10
pengweiqhca/Xunit.DependencyInjection
Add Github Actions CI https://github.com/pengweiqhca/Xunit.DependencyInjection/pull/55
Update template https://github.com/pengweiqhca/Xunit.DependencyInjection/pull/59
StackExchange/StackExchange.Redis
Add support for GETDEL command https://github.com/StackExchange/StackExchange.Redis/pull/1840
Makes StreamEntry constructor public https://github.com/StackExchange/StackExchange.Redis/pull/1923
Tyrrrz/CliWrap
Remove unused dependencies https://github.com/Tyrrrz/CliWrap/pull/132
ua-parser/uap-csharp
Update target framework for netstandard2.0 https://github.com/ua-parser/uap-csharp/pull/65
希望接下來的一年能夠有更多更高質(zhì)量的開源貢獻(xiàn)~
很多開源項(xiàng)目的貢獻(xiàn)很簡(jiǎn)單并不會(huì)很復(fù)雜,大家也可以盡可能的貢獻(xiàn)一些自己的力量來讓 .NET 社區(qū)的開源項(xiàng)目越來越好~
Sample
上面的統(tǒng)計(jì)結(jié)果來自上面提到的 API
-?author?用戶名 -?type=pr?返回?PR -?is:merged?過濾合并的?PR -?merged:?根據(jù)?PR?合并時(shí)間過濾 -?page:?當(dāng)前頁碼,默認(rèn)是?1,?用來分頁Github API result上面的返回結(jié)果中的 html_url 對(duì)應(yīng)的就是對(duì)應(yīng) PR 的 HTML 頁面地址, title/body 對(duì)應(yīng) PR 的標(biāo)題和描述信息,created_at 和 closed_at 分別對(duì)應(yīng) PR 的創(chuàng)建和合并時(shí)間
寫了一個(gè)簡(jiǎn)單的小程序來統(tǒng)計(jì)結(jié)果,示例代碼如下:
using?System.Net.Http.Json; using?System.Text.Json.Nodes; using?WeihanLi.Extensions;const?int?pageCount?=?30; const?string?userName?=?"weihanli"; const?string?urlFormat?=$"search/issues?page={{0}}&q=author%3A{userName}+type%3Apr+is:merged+merged:%3E=2021-01-01";var?prList?=?new?List<GithubPRModel>(); var?itemsCount?=?0; var?pageNum?=?1;using?var?httpClient?=?new?HttpClient() {BaseAddress?=?new?Uri("https://api.github.com/") }; //?https://docs.github.com/en/rest/overview/resources-in-the-rest-api#user-agent-required httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent",?"Mozilla/5.0?(Windows?NT?10.0;?Win64;?x64)?AppleWebKit/537.36?(KHTML,?like?Gecko)?Chrome/97.0.4692.99?Safari/537.36");do {var?url?=?urlFormat.FormatWith(pageNum.ToString());using?var?response?=?await?httpClient.GetAsync(url);var?responseText?=?await?response.Content.ReadAsStringAsync();var?responseObj?=?JsonNode.Parse(responseText);ArgumentNullException.ThrowIfNull(responseObj);var?items?=?responseObj["items"]?.AsArray();ArgumentNullException.ThrowIfNull(items);itemsCount?=?items.Count;foreach?(var?item?in?items){prList.Add(new?GithubPRModel(){Title?=?item["title"]?.GetValue<string>(),Body?=?item["body"]?.GetValue<string>(),Url?=?item["html_url"]?.GetValue<string>(),CreatedAt?=?item["created_at"]?.GetValue<DateTimeOffset>(),ClosedAt?=?item["closed_at"]?.GetValue<DateTimeOffset>()});}pageNum++; }?while?(itemsCount?==?pageCount);var?totalCount?=?prList.Count; prList.RemoveAll(x?=>?userName.Equals(x.UserName,?StringComparison.OrdinalIgnoreCase)); var?excludedCount?=?prList.Count; Console.WriteLine($"Total:{totalCount},?excludedCount:?{excludedCount}");Console.WriteLine("Completed"); Console.ReadLine();internal?class?GithubPRModel {private?string?_url;public?string?Title?{?get;?set;?}public?string?Body?{?get;?set;?}public?DateTimeOffset??CreatedAt?{?get;?set;?}public?DateTimeOffset??ClosedAt?{?get;?set;?}public?string?Url{get?=>?_url;set{_url?=?value;if?(!string.IsNullOrEmpty(_url)){var?index?=?_url.IndexOf("/pull/",?StringComparison.OrdinalIgnoreCase);RepoUrl?=?_url[..index];RepoName?=?RepoUrl.Replace("https://github.com/",?"");UserName?=?RepoName[..RepoName.IndexOf('/')];}}}public?string?UserName?{?get;?private?set;?}public?string?RepoName?{?get;?private?set;?}public?string?RepoUrl?{?get;?private?set;?} }上面的結(jié)果就是用這個(gè)示例中的代碼生成的,為了方便也可以改造一下上面的代碼直接生成 Markdown 內(nèi)容,上面的貢獻(xiàn)內(nèi)容就是下面這段生成 markdown 的代碼生成出來的,你也可以根據(jù)自己需要進(jìn)行一些定制
var?mdContent?=?prList.GroupBy(g?=>?new {g.RepoName,g.RepoUrl }) .OrderBy(g?=>?g.Key.RepoName) .Select(g?=>?$@"-?[{g.Key.RepoName}]({g.Key.RepoUrl}) {g.OrderBy(x?=>?x.CreatedAt).Select(x?=>?$"??-?{x.Title}?<{x.Url}>").StringJoin(Environment.NewLine)} ") .StringJoin(Environment.NewLine);await?File.WriteAllTextAsync("result.md",?mdContent);StringJoin 是一個(gè)基于 string.Join 的擴(kuò)展方法
More
上面的示例中有一個(gè)需要注意的地方就是 UserAgent 請(qǐng)求頭的配置,如果不配置,Github 就會(huì)返回一個(gè) 403?
可以參考 Github 文檔?https://docs.github.com/en/rest/overview/resources-in-the-rest-api#user-agent-required
另外還有一些可以優(yōu)化的地方,比如說可以使用 System.Text.Json 的 GetFromJsonAsync 方法來簡(jiǎn)化 http response JSON 反序列化
另外可以考慮使用 Github 提供的客戶端,因?yàn)槲业男枨蟊容^簡(jiǎn)單所以直接調(diào)了這個(gè) API,也可以考慮使用 Github 客戶端?octokit
References
https://api.github.com/search/issues?page=1&q=state%3Aclosed+author%3Aweihanli+type%3Apr+is:merged+merged:%3E=2021-01-01
https://docs.github.com/en/rest/overview/resources-in-the-rest-api#user-agent-required
https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests#search-based-on-the-state-of-an-issue-or-pull-request
https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests#search-by-author
https://stackoverflow.com/questions/17412809/how-to-get-my-pull-requests-from-github-api
https://github.com/WeihanLi/SamplesInPractice/blob/master/GithubAPISample/Program.cs
https://github.com/octokit/octokit.net
總結(jié)
以上是生活随笔為你收集整理的统计 Github 2021 贡献过的开源项目的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 违反Apache 2.0许可证再分发被指
- 下一篇: 【Blog.Core开源】网关统一集成下