Skip to content

Added organisation name button #141

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 4 commits into
base: master
Choose a base branch
from

Conversation

Preeti9764
Copy link
Contributor

@Preeti9764 Preeti9764 commented Jun 19, 2025

📌 Fixes

Fixes #140


📝 Summary of Changes

Added an organisation name input button in the settings for the user to switch organisations easily, and can fetch GitHub activities made for that particular organisation.It is set default to fossasia and user can change it for there org.


📸 Screenshots / Demo (if UI-related)

image


✅ Checklist

  • I’ve tested my changes locally

  • My code follows the project’s code style guidelines

Summary by Sourcery

Enable dynamic organization selection and enhance data fetching and UI styles.

New Features:

  • Add an organisation name input in the settings UI to allow switching between GitHub organisations.
  • Update the GitHub data fetching logic to include the user-specified organisation when querying issues and pull requests.

Enhancements:

  • Automatically clear and reload the cache when the organisation name changes.
  • Improve caching logic to better manage API responses and queuing.
  • Enhance UI styling with consistent formatting, dark-mode support, and custom toast notifications.

Copy link
Contributor

sourcery-ai bot commented Jun 19, 2025

Reviewer's Guide

This PR extends the settings UI with an organisation name input for dynamic GitHub org selection and integrates it into the data‐fetch logic, refactors the caching layer to use a configurable TTL and request queuing (clearing cache on org change), and enhances front‐end styling with dark‐mode support and custom toast notifications.

Sequence diagram for organisation name affecting GitHub data fetch and cache

sequenceDiagram
    actor User
    participant SettingsUI as Settings UI
    participant Storage as chrome.storage.local
    participant Cache as githubCache
    participant ScrumHelper as fetchGithubData()
    participant GitHub as GitHub API

    User->>SettingsUI: Enter organisation name
    SettingsUI->>Storage: Save organisationName
    SettingsUI->>Cache: Clear githubCache
    User->>SettingsUI: Click Generate Report
    SettingsUI->>ScrumHelper: Trigger data fetch
    ScrumHelper->>Storage: Get organisationName
    ScrumHelper->>GitHub: Fetch issues/PRs for organisation
    GitHub-->>ScrumHelper: Return data
    ScrumHelper->>Cache: Save new data
    ScrumHelper->>SettingsUI: Update scrum report
Loading

Class diagram for updated caching and settings logic

classDiagram
    class SettingsUI {
        +organisationName: string
        +cacheInput: number
        +onOrganisationNameBlur()
        +onCacheInputBlur()
    }
    class githubCache {
        +data
        +cacheKey
        +timestamp
        +ttl
        +fetching
        +queue
        +subject
        +saveToStorage()
        +loadFromStorage()
        +clearOnOrgChange()
    }
    class ScrumHelper {
        +fetchGithubData()
        +processGithubData()
    }
    SettingsUI --|> githubCache : clears cache on org change
    SettingsUI --|> ScrumHelper : triggers fetch
    ScrumHelper --|> githubCache : uses cache
    githubCache o-- Storage : persists data
Loading

File-Level Changes

Change Details Files
Introduce organisationName input and integrate into data fetching
  • add <input id="organisationName"> in settings UI
  • persist organisationName to chrome.storage on blur and clear cache when changed
  • update fetchGithubData to read organisationName (default: 'fossasia') and include it in GitHub API URLs
src/popup.html
src/scripts/popup.js
src/scripts/scrumHelper.js
Refactor cache management with dynamic TTL and request queuing
  • extract getCacheTTL, saveToStorage, and loadFromStorage helpers
  • use cacheInput from storage to set cache TTL and clear cache on org change
  • implement queuing of concurrent fetch calls and conditional cache usage
src/scripts/scrumHelper.js
Enhance UI styling, dark mode support, and custom toasts
  • add dark‐mode classes and transitions for components in CSS
  • define custom Materialize toast styles for normal and dark modes
  • tweak layout and class names in popup.html for consistent formatting
src/index.css
src/popup.html

Assessment against linked issues

Issue Objective Addressed Explanation
#140 Allow users to select the GitHub organization for fetching activities in their Scrum report.

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

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 - here's some feedback:

  • Include organisationName in your cacheKey (e.g. ${githubUsername}-${organisationName}-${startingDate}-${endingDate}) so switching orgs automatically fetches fresh data instead of relying on manual cache clears.
  • Add basic validation for the organisationName input (e.g. non-empty, valid GitHub org pattern) and provide UI feedback if the entered value is invalid.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Include `organisationName` in your cacheKey (e.g. `${githubUsername}-${organisationName}-${startingDate}-${endingDate}`) so switching orgs automatically fetches fresh data instead of relying on manual cache clears.
- Add basic validation for the organisationName input (e.g. non-empty, valid GitHub org pattern) and provide UI feedback if the entered value is invalid.

## Individual Comments

### Comment 1
<location> `src/scripts/popup.js:430` </location>
<code_context>
     });
-
+}
+if (organisationNameInput) {
+    chrome.storage.local.get(['organisationName'], function (result) {
+        if (result.organisationName) {
+            organisationNameInput.value = result.organisationName;
+        } else {
+            organisationNameInput.value = 'fossasia';
+        }
+    });
+    organisationNameInput.addEventListener('blur', function () {
+        let orgValue = this.value.trim() || 'fossasia';
</code_context>

<issue_to_address>
Cache is cleared on every organisation name blur, even if unchanged.

Only clear the cache if the organisation name value has changed to avoid unnecessary invalidations.
</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.

body.classList.add('dark-mode');
darkModeToggle.src = 'icons/light-mode.png';
if(settingsIcon) {
if (settingsIcon) {
settingsIcon.src = 'icons/settings-night.png'; // Changed from settings-night.png
}
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (performance): Cache is cleared on every organisation name blur, even if unchanged.

Only clear the cache if the organisation name value has changed to avoid unnecessary invalidations.

Comment on lines +135 to +138
function handleLastWeekContributionChange() {
endingDate = getToday();
startingDate = getLastWeek();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (avoid-function-declarations-in-blocks)

ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.

Comment on lines +139 to +142
function handleYesterdayContributionChange() {
endingDate = getToday();
startingDate = getYesterday();
}
function getLastWeek() {
let today = new Date();
let lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7);
let lastWeekMonth = lastWeek.getMonth() + 1;
let lastWeekDay = lastWeek.getDate();
let lastWeekYear = lastWeek.getFullYear();
let lastWeekDisplayPadded =
('0000' + lastWeekYear.toString()).slice(-4) +
'-' +
('00' + lastWeekMonth.toString()).slice(-2) +
'-' +
('00' + lastWeekDay.toString()).slice(-2);
return lastWeekDisplayPadded;
}
function getYesterday() {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (avoid-function-declarations-in-blocks)

ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.

Comment on lines +143 to +156
function getLastWeek() {
let today = new Date();
let lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7);
let lastWeekMonth = lastWeek.getMonth() + 1;
let lastWeekDay = lastWeek.getDate();
let lastWeekYear = lastWeek.getFullYear();
let lastWeekDisplayPadded =
('0000' + lastWeekYear.toString()).slice(-4) +
'-' +
('00' + lastWeekMonth.toString()).slice(-2) +
'-' +
('00' + lastWeekDay.toString()).slice(-2);
return lastWeekDisplayPadded;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (avoid-function-declarations-in-blocks)

ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.

let project = repository_url.substr(repository_url.lastIndexOf('/') + 1);
let title = item.title;
let number = item.number;
let html_url = item.html_url;
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)

Suggested change
let html_url = item.html_url;
let {html_url} = item;


ExplanationObject destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.

From the Airbnb Javascript Style Guide

Comment on lines +656 to +666
function triggerScrumGeneration() {
if (issuesDataProcessed && prsReviewDataProcessed) {
log('Both data sets processed, generating scrum body.');
writeScrumBody();
} else {
log('Waiting for all data to be processed before generating scrum.', {
issues: issuesDataProcessed,
reviews: prsReviewDataProcessed,
});
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Avoid function declarations, favouring function assignment expressions, inside blocks. (avoid-function-declarations-in-blocks)

ExplanationFunction declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers. Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you should use function expressions, which create functions in-scope.

}

function writeGithubIssuesPrs() {
let items = githubIssuesData.items;
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)

Suggested change
let items = githubIssuesData.items;
let {items} = githubIssuesData;


ExplanationObject destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.

From the Airbnb Javascript Style Guide

}
for (let i = 0; i < items.length; i++) {
let item = items[i];
let html_url = item.html_url;
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)

Suggested change
let html_url = item.html_url;
let {html_url} = item;


ExplanationObject destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.

From the Airbnb Javascript Style Guide

@Preeti9764 Preeti9764 requested review from vedansh-5 and hpdang June 19, 2025 12:08
@Preeti9764 Preeti9764 self-assigned this Jun 20, 2025
@Preeti9764
Copy link
Contributor Author

Preeti9764 commented Jun 21, 2025

@hpdang Please share your views on this to ... it will reduce the hectic of making code changes for different organisation users. Thanks!

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.

Add functionality to allow user to Select Organisation.
2 participants