Skip to content

Commit ad43f61

Browse files
committed
Filter inherited stats by ownership
1 parent ef574fa commit ad43f61

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
EXCLUDE_REPOS: ${{ secrets.EXCLUDE_REPOS }}
4646
EXCLUDE_LANGS: ${{ secrets.EXCLUDE_LANGS }}
4747
EXCLUDE_PRIVATE: "false"
48+
EXCLUDE_INHERITED: "true"
4849
SILENT: "true"
4950
# TODO: Remove this when they get their API working again
5051
# https://github.com/orgs/community/discussions/192970

src/main.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const Args = struct {
4545
exclude_repos: ?[]const u8 = null,
4646
exclude_langs: ?[]const u8 = null,
4747
exclude_private: bool = false,
48+
exclude_inherited: bool = false,
4849
overview_output_file: ?[]const u8 = null,
4950
languages_output_file: ?[]const u8 = null,
5051
overview_template: ?[]const u8 = null,
@@ -274,6 +275,9 @@ pub fn main(init: std.process.Init) !void {
274275
{
275276
continue;
276277
}
278+
const is_owned = !repository.fork and
279+
std.mem.eql(u8, repository.owner_login, stats.user);
280+
if (args.exclude_inherited and !is_owned) continue;
277281
aggregate_stats.stars += repository.stars;
278282
aggregate_stats.forks += repository.forks;
279283
aggregate_stats.lines_changed += repository.lines_changed;

src/statistics.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ const Repository = struct {
2222
lines_changed: u32,
2323
views: u32,
2424
private: bool,
25+
fork: bool,
26+
owner_login: []const u8,
2527

2628
pub fn deinit(self: @This(), allocator: std.mem.Allocator) void {
2729
allocator.free(self.name);
30+
allocator.free(self.owner_login);
2831
if (self.languages) |languages| {
2932
for (languages) |language| {
3033
language.deinit(allocator);
@@ -264,6 +267,8 @@ fn getReposByYear(
264267
\\ stargazerCount
265268
\\ forkCount
266269
\\ isPrivate
270+
\\ isFork
271+
\\ owner { login }
267272
\\ languages(
268273
\\ first: 100,
269274
\\ orderBy: { direction: DESC, field: SIZE }
@@ -320,6 +325,8 @@ fn getReposByYear(
320325
stargazerCount: u32,
321326
forkCount: u32,
322327
isPrivate: bool,
328+
isFork: bool,
329+
owner: struct { login: []const u8 },
323330
languages: ?struct {
324331
edges: ?[]struct {
325332
size: u32,
@@ -388,9 +395,11 @@ fn getReposByYear(
388395
}
389396
var repository = Repository{
390397
.name = try context.allocator.dupe(u8, raw_repo.nameWithOwner),
398+
.owner_login = try context.allocator.dupe(u8, raw_repo.owner.login),
391399
.stars = raw_repo.stargazerCount,
392400
.forks = raw_repo.forkCount,
393401
.private = raw_repo.isPrivate,
402+
.fork = raw_repo.isFork,
394403
.languages = null,
395404
.views = 0,
396405
.lines_changed = 0,

0 commit comments

Comments
 (0)