Skip to content

Populate reusedCode with fork upstream parent#127

Merged
haseebmalik18 merged 4 commits into
DSACMS:devfrom
haseebmalik18:DSACMS/haseeb/reusedCodeFromForks
Jul 13, 2026
Merged

Populate reusedCode with fork upstream parent#127
haseebmalik18 merged 4 commits into
DSACMS:devfrom
haseebmalik18:DSACMS/haseeb/reusedCodeFromForks

Conversation

@haseebmalik18

@haseebmalik18 haseebmalik18 commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

When a repository is a fork, its upstream parent is now auto-added to reusedCode instead of relying on manual entry.

Changes

  • detectForkParent() helper reads fork / parent from the GitHub repo API and returns a reusedCode entry (or null if not a fork or on error)
  • getMetaData folds the fork upstream into reusedCode alongside detected gov dependencies, de-duped against existing entries via mergeReusedCode

Testing

  • 5 new unit tests (fork, non-fork, missing parent, API failure, getMetaData wiring): 261/261 pass
  • Verified end-to-end against the live GitHub API: a real fork yields its upstream, a non-fork yields []

closes: #94

@sachin-panayil

Copy link
Copy Markdown
Collaborator

i'll fully review this after #125 gets merged but upon initial review, it looks good to me

@natalialuzuriaga natalialuzuriaga left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing job incorporating the fork functionality!! All LGTM!

Comment thread src/helper.ts
Comment on lines +130 to +145
async function detectForkParent(): Promise<ReusedCodeEntry | null> {
try {
const repoData = await octokit.rest.repos.get({ owner, repo });
const { fork, parent } = repoData.data;

if (!fork || !parent) return null;

return {
name: parent.full_name,
URL: parent.html_url,
};
} catch (error) {
log.error(`Failed to detect fork parent: ${error}`);
return null;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES logic is great here 🔥

Comment thread src/main.ts Outdated
Comment on lines +144 to +147
const reusedCode = mergeReusedCode(existingCodeJSON?.reusedCode ?? [], [
...(forkParent ? [forkParent] : []),
...detectedDeps,
]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like how you used the existing merge function not just to merge the original deps with the newly generated deps but to also add forkParent too -- great use of this function!

@haseebmalik18 haseebmalik18 changed the title Dsacms/haseeb/reused code from forks Populate reusedCode with fork upstream parent Jul 9, 2026
…CodeFromForks

# Conflicts:
#	src/__tests__/unit/helper.test.ts
#	src/helper.ts
#	src/main.ts
@haseebmalik18

Copy link
Copy Markdown
Collaborator Author

@sachin-panayil if you can review this aswell #125 is merged

@sachin-panayil sachin-panayil left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work 👍

@haseebmalik18
haseebmalik18 merged commit 4da25dd into DSACMS:dev Jul 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metadata: Populate reusedCode with forks

3 participants