Skip to content

Fetch all github activities #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

Preeti9764
Copy link
Contributor

@Preeti9764 Preeti9764 commented Jun 27, 2025

πŸ“Œ Fixes

Fixes #142


πŸ“ Summary of Changes

  • Fetch all your GitHub activities on public repositories when the organization name is not provided.

πŸ“Έ Screenshots / Demo (if UI-related)

image


βœ… Checklist

  • I’ve tested my changes locally
  • I’ve added tests (if applicable)
  • I’ve updated documentation (if applicable)
  • My code follows the project’s code style guidelines

Summary by Sourcery

Allow fetching GitHub activities from all public repositories by making the organization filter optional, updating cache keys and query construction accordingly, and enhancing the popup input handling and debug logging

New Features:

  • Fetch user GitHub activities across all public repositories when no organization is specified

Enhancements:

  • Include organization name in cache key and API payload to separate caches per organization
  • Omit the org: filter in GitHub API queries when the organization name is empty
  • Allow clearing the organization input in the popup to reset orgName and fetch across all public repos
  • Add extensive console logging throughout the data fetch, processing, and rendering functions for improved debugging and traceability

Copy link
Contributor

sourcery-ai bot commented Jun 27, 2025

Reviewer's Guide

This PR removes the hardcoded default organization, enables fetching GitHub activities across all public repositories when no org is specified, and instruments the fetching and rendering logic with enhanced cache-key handling and debug logging.

Sequence diagram for fetching GitHub activities with or without organization

sequenceDiagram
    actor User
    participant Popup as Popup UI
    participant Storage as chrome.storage.local
    participant ScrumHelper as scrumHelper.js
    participant GitHub as GitHub API

    User->>Popup: Enter GitHub username and (optionally) org
    Popup->>Storage: Save orgName (can be empty)
    User->>Popup: Click Generate Report
    Popup->>ScrumHelper: Trigger allIncluded('popup')
    ScrumHelper->>Storage: Get orgName, username, dates
    ScrumHelper->>ScrumHelper: Build cacheKey (includes orgName or 'all')
    ScrumHelper->>GitHub: Fetch issues & PRs (with orgName if set, else all public)
    GitHub-->>ScrumHelper: Return issues & PRs
    ScrumHelper->>ScrumHelper: Process and cache data
    ScrumHelper->>Popup: Render report in popup
    Popup->>User: Show generated report
Loading

Class diagram for updated scrumHelper.js data flow

classDiagram
    class ScrumHelper {
        - orgName: string
        - githubUsername: string
        - githubToken: string
        - startingDate: string
        - endingDate: string
        - githubCache: object
        + allIncluded(outputTarget)
        + fetchGithubData()
        + processGithubData(data)
        + writeScrumBody()
        + writeGithubPrsReviews()
        + triggerScrumGeneration()
    }
    class chrome.storage.local {
        + get(keys, callback)
        + set(items, callback)
    }
    class GitHubAPI {
        + searchIssues(query)
        + getUser(username)
    }
    ScrumHelper --> "1" chrome.storage.local : uses
    ScrumHelper --> "1" GitHubAPI : fetches data from
Loading

File-Level Changes

Change Details Files
Remove default orgName and update storage retrieval to accept empty org
  • Initialized orgName to empty string instead of hardcoded default
  • Restored orgName from storage only when defined, with logging
  • In popup.js, clear orgName in storage on empty input and prevent auto-fallback
src/scripts/scrumHelper.js
src/scripts/popup.js
Adjust cache key and API query to include optional org filtering
  • Extended cache key to incorporate orgName or 'all'
  • Constructed orgPart for API query only when orgName is nonempty
  • Passed orgName in fetch payload to server helper
src/scripts/scrumHelper.js
Instrument key functions with detailed debug logging
  • Added console.log statements around orgName, cacheKey, URLs, and API responses
  • Wrapped processGithubData, writeScrumBody, writeGithubPrsReviews, triggerScrumGeneration with log() calls
  • Logged element lookups and error conditions for popup/email contexts
src/scripts/scrumHelper.js
Minor UI and markup tweaks in popup and HTML
  • Removed extraneous blank lines in popup.js
  • Added a blank line in popup.html for consistent formatting
src/scripts/popup.js
src/popup.html

Assessment against linked issues

Issue Objective Addressed Explanation
#142 Fetch all GitHub activities, including those in personal repos, when no organization name is set. βœ…
#142 Provide an option to choose whether to fetch activities from all repos or only from a specific organization. βœ…

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Preeti9764 Preeti9764 self-assigned this Jun 27, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Preeti9764 - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/scripts/scrumHelper.js:365` </location>
<code_context>

-		let issueUrl = `https://api.github.com/search/issues?q=author%3A${githubUsername}+org%3A${orgName}+created%3A${startingDate}..${endingDate}&per_page=100`;
-		let prUrl = `https://api.github.com/search/issues?q=commenter%3A${githubUsername}+org%3A${orgName}+updated%3A${startingDate}..${endingDate}&per_page=100`;
+		// Build org part for query only if orgName is set and not empty
+		console.log('[SCRUM-HELPER] orgName before API query:', orgName);
+		let orgPart = orgName && orgName.trim() ? `+org%3A${orgName}` : '';
+		console.log('[SCRUM-HELPER] orgPart for API:', orgPart);
+		let issueUrl = `https://api.github.com/search/issues?q=author%3A${githubUsername}${orgPart}+created%3A${startingDate}..${endingDate}&per_page=100`;
+		let prUrl = `https://api.github.com/search/issues?q=commenter%3A${githubUsername}${orgPart}+updated%3A${startingDate}..${endingDate}&per_page=100`;
+		console.log('[SCRUM-HELPER] issueUrl:', issueUrl);
+		console.log('[SCRUM-HELPER] prUrl:', prUrl);
</code_context>

<issue_to_address>
Query construction for orgName may result in malformed queries if orgName contains special characters.

URL-encode orgName before adding it to the query string to prevent API errors from special characters.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
		// Build org part for query only if orgName is set and not empty
		console.log('[SCRUM-HELPER] orgName before API query:', orgName);
		let orgPart = orgName && orgName.trim() ? `+org%3A${orgName}` : '';
		console.log('[SCRUM-HELPER] orgPart for API:', orgPart);
		let issueUrl = `https://api.github.com/search/issues?q=author%3A${githubUsername}${orgPart}+created%3A${startingDate}..${endingDate}&per_page=100`;
		let prUrl = `https://api.github.com/search/issues?q=commenter%3A${githubUsername}${orgPart}+updated%3A${startingDate}..${endingDate}&per_page=100`;
		console.log('[SCRUM-HELPER] issueUrl:', issueUrl);
		console.log('[SCRUM-HELPER] prUrl:', prUrl);
=======
		// Build org part for query only if orgName is set and not empty, and URL-encode orgName
		console.log('[SCRUM-HELPER] orgName before API query:', orgName);
		let encodedOrgName = orgName && orgName.trim() ? encodeURIComponent(orgName) : '';
		let orgPart = encodedOrgName ? `+org%3A${encodedOrgName}` : '';
		console.log('[SCRUM-HELPER] orgPart for API:', orgPart);
		let issueUrl = `https://api.github.com/search/issues?q=author%3A${githubUsername}${orgPart}+created%3A${startingDate}..${endingDate}&per_page=100`;
		let prUrl = `https://api.github.com/search/issues?q=commenter%3A${githubUsername}${orgPart}+updated%3A${startingDate}..${endingDate}&per_page=100`;
		console.log('[SCRUM-HELPER] issueUrl:', issueUrl);
		console.log('[SCRUM-HELPER] prUrl:', prUrl);
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click πŸ‘ or πŸ‘Ž on each comment and I'll use the feedback to improve your reviews.

Comment on lines 365 to 372
// Build org part for query only if orgName is set and not empty
console.log('[SCRUM-HELPER] orgName before API query:', orgName);
let orgPart = orgName && orgName.trim() ? `+org%3A${orgName}` : '';
console.log('[SCRUM-HELPER] orgPart for API:', orgPart);
let issueUrl = `https://api.github.com/search/issues?q=author%3A${githubUsername}${orgPart}+created%3A${startingDate}..${endingDate}&per_page=100`;
let prUrl = `https://api.github.com/search/issues?q=commenter%3A${githubUsername}${orgPart}+updated%3A${startingDate}..${endingDate}&per_page=100`;
console.log('[SCRUM-HELPER] issueUrl:', issueUrl);
console.log('[SCRUM-HELPER] prUrl:', prUrl);
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Query construction for orgName may result in malformed queries if orgName contains special characters.

URL-encode orgName before adding it to the query string to prevent API errors from special characters.

Suggested change
// Build org part for query only if orgName is set and not empty
console.log('[SCRUM-HELPER] orgName before API query:', orgName);
let orgPart = orgName && orgName.trim() ? `+org%3A${orgName}` : '';
console.log('[SCRUM-HELPER] orgPart for API:', orgPart);
let issueUrl = `https://api.github.com/search/issues?q=author%3A${githubUsername}${orgPart}+created%3A${startingDate}..${endingDate}&per_page=100`;
let prUrl = `https://api.github.com/search/issues?q=commenter%3A${githubUsername}${orgPart}+updated%3A${startingDate}..${endingDate}&per_page=100`;
console.log('[SCRUM-HELPER] issueUrl:', issueUrl);
console.log('[SCRUM-HELPER] prUrl:', prUrl);
// Build org part for query only if orgName is set and not empty, and URL-encode orgName
console.log('[SCRUM-HELPER] orgName before API query:', orgName);
let encodedOrgName = orgName && orgName.trim() ? encodeURIComponent(orgName) : '';
let orgPart = encodedOrgName ? `+org%3A${encodedOrgName}` : '';
console.log('[SCRUM-HELPER] orgPart for API:', orgPart);
let issueUrl = `https://api.github.com/search/issues?q=author%3A${githubUsername}${orgPart}+created%3A${startingDate}..${endingDate}&per_page=100`;
let prUrl = `https://api.github.com/search/issues?q=commenter%3A${githubUsername}${orgPart}+updated%3A${startingDate}..${endingDate}&per_page=100`;
console.log('[SCRUM-HELPER] issueUrl:', issueUrl);
console.log('[SCRUM-HELPER] prUrl:', prUrl);

@Preeti9764 Preeti9764 marked this pull request as draft June 27, 2025 12:21
@vedansh-5
Copy link
Contributor

test update

@Preeti9764 Preeti9764 marked this pull request as ready for review June 29, 2025 16:17
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Preeti9764 - I've reviewed your changes and they look great!

Blocking issues:

  • User controlled data in methods like innerHTML, outerHTML or document.write is an anti-pattern that can lead to XSS vulnerabilities (link)
  • User controlled data in a scrumReport.innerHTML is an anti-pattern that can lead to XSS vulnerabilities (link)
Prompt for AI Agents
Please address the comments from this code review:
## Security Issues

### Issue 1
<location> `src/scripts/scrumHelper.js:496` </location>

<issue_to_address>
**security (opengrep-rules.javascript.browser.security.insecure-document-method):** User controlled data in methods like `innerHTML`, `outerHTML` or `document.write` is an anti-pattern that can lead to XSS vulnerabilities

*Source: opengrep*
</issue_to_address>

### Issue 2
<location> `src/scripts/scrumHelper.js:496` </location>

<issue_to_address>
**security (opengrep-rules.javascript.browser.security.insecure-innerhtml):** User controlled data in a `scrumReport.innerHTML` is an anti-pattern that can lead to XSS vulnerabilities

*Source: opengrep*
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click πŸ‘ or πŸ‘Ž on each comment and I'll use the feedback to improve your reviews.

if (scrumReport) {
let errorMsg = 'An error occurred while generating the report.';
if (err) {
if (typeof err === 'string') errorMsg = err;
else if (err.message) errorMsg = err.message;
else errorMsg = JSON.stringify(err)
}

scrumReport.innerHTML = `<div class="error-message" style="color: #dc2626; font-weight: bold; padding: 10px;">${err.message || 'An error occurred while generating the report.'}</div>`;
Copy link
Contributor

Choose a reason for hiding this comment

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

security (opengrep-rules.javascript.browser.security.insecure-document-method): User controlled data in methods like innerHTML, outerHTML or document.write is an anti-pattern that can lead to XSS vulnerabilities

Source: opengrep

if (scrumReport) {
let errorMsg = 'An error occurred while generating the report.';
if (err) {
if (typeof err === 'string') errorMsg = err;
else if (err.message) errorMsg = err.message;
else errorMsg = JSON.stringify(err)
}

scrumReport.innerHTML = `<div class="error-message" style="color: #dc2626; font-weight: bold; padding: 10px;">${err.message || 'An error occurred while generating the report.'}</div>`;
Copy link
Contributor

Choose a reason for hiding this comment

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

security (opengrep-rules.javascript.browser.security.insecure-innerhtml): User controlled data in a scrumReport.innerHTML is an anti-pattern that can lead to XSS vulnerabilities

Source: opengrep

@Preeti9764 Preeti9764 requested review from hpdang and vedansh-5 June 29, 2025 16:21
@Preeti9764
Copy link
Contributor Author

@hpdang @vedansh-5 Please review this and share your feedback, it will more enhanced as the changes of pr#164 got merged .Thanks!

@vedansh-5
Copy link
Contributor

@hpdang @vedansh-5 Please review this and share your feedback, it will more enhanced as the changes of pr#164 got merged .Thanks!

Sure, I will make a review soon, I am currently facing rate limitation from github.com due to using public requests while testing.
I'll make the review later tonight. Thanks!

Copy link
Contributor

@vedansh-5 vedansh-5 left a comment

Choose a reason for hiding this comment

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

Left a few comments, thank you.

@@ -335,6 +349,7 @@ function allIncluded(outputTarget = 'email') {
username: githubUsername,
startDate: startingDate,
endDate: endingDate,
orgName: orgName || 'all'
Copy link
Contributor

Choose a reason for hiding this comment

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

image
Different API calls are being made for fetching all of the data. Since a user could have contributed to a number of orgs, these different api calls will result in public api limit exemption.
We can have this feature as a token-only feature to not let it affect the primary functionality of out behavior.
In the current implementation, the limit would be reached soon if we are using public requests.
@hpdang Please share your views on this.

Suggestion - Even while making auth requests we can use graphQL to fetch all the contributions in one request and, and have the current issueUrls and prReviewedUrls for public requests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vedansh-5 this request are for the different labels of pr, not for the github actvities fetched. I hope this clears you confusion .Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

@vedansh-5 this request are for the different labels of pr, not for the github actvities fetched. I hope this clears you confusion .Thanks!

Thanks for clearing it out!

Comment on lines 409 to 419
console.log('[SCRUM-HELPER] orgName before API query:', orgName);
console.log('[SCRUM-HELPER] orgName type:', typeof orgName);
console.log('[SCRUM-HELPER] orgName length:', orgName ? orgName.length : 0);
let orgPart = orgName && orgName.trim() ? `+org%3A${orgName}` : '';
console.log('[SCRUM-HELPER] orgPart for API:', orgPart);
console.log('[SCRUM-HELPER] orgPart length:', orgPart.length);
let issueUrl = `https://api.github.com/search/issues?q=author%3A${githubUsername}${orgPart}+created%3A${startingDate}..${endingDate}&per_page=100`;
let prUrl = `https://api.github.com/search/issues?q=commenter%3A${githubUsername}${orgPart}+updated%3A${startingDate}..${endingDate}&per_page=100`;
console.log('[SCRUM-HELPER] issueUrl:', issueUrl);
console.log('[SCRUM-HELPER] prUrl:', prUrl);
let userUrl = `https://api.github.com/users/${githubUsername}`;
Copy link
Contributor

@vedansh-5 vedansh-5 Jun 30, 2025

Choose a reason for hiding this comment

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

Even after clearing the orgName, the data is fetched for the previously set org even after the org is cleared.
It generates the correct data only after hitting the generate button again.

allRev1.mp4

@Preeti9764 Preeti9764 marked this pull request as draft July 2, 2025 04:39
@Preeti9764 Preeti9764 marked this pull request as ready for review July 2, 2025 15:57
@hpdang
Copy link
Member

hpdang commented Jul 4, 2025

@Preeti9764 this is the next thing we should have

@Preeti9764
Copy link
Contributor Author

@hpdang Made the changes , Please have a look whenever you get time.Thanks!

@Preeti9764 Preeti9764 requested a review from vedansh-5 July 5, 2025 19:01
@Preeti9764
Copy link
Contributor Author

@vedansh-5 Share your views. thanks!

Copy link
Contributor

@vedansh-5 vedansh-5 left a comment

Choose a reason for hiding this comment

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

lgtm! Thanks @Preeti9764

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.

Fetching all github activites in the selected time period
3 participants