Skip to content
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

Added the latest repo version in about section of Settings page #970

Merged

Conversation

navishmonga
Copy link
Contributor

Fixes issue #967

I have added the tag which will fetch the latest version of the release from the github repo and show it in the about section of settings page.

Copy link

coderabbitai bot commented Oct 15, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in the Settings component of Client/src/Pages/Settings/index.jsx involve the addition of functionality to fetch the latest release version from a GitHub repository using the useEffect hook. An asynchronous function, fetchLatestVersion, is defined to make a GET request to the GitHub API, updating the state variable version with the fetched tag_name. Error handling is also implemented to notify users in case of a failure. Additionally, the GitHub link is updated, and a new state variable version is initialized and displayed in the component.

Changes

File Change Summary
Client/src/Pages/Settings/index.jsx - Added useEffect for fetching the latest version from GitHub.
- Introduced state variable const [version, setVersion] = useState("unknown");.
- Updated GitHub link to the specific repository for the uptime project.
- Added error handling with toast notification for fetch failures.
- Added prop type isAdmin: PropTypes.bool.
Client/src/Utils/NetworkService.js - Added asynchronous method fetchGithubLatestRelease() for retrieving the latest release version from GitHub.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Settings
    participant GitHubAPI

    User->>Settings: Load Settings Component
    Settings->>GitHubAPI: GET latest release version
    GitHubAPI-->>Settings: Return latest version (tag_name)
    Settings->>Settings: Update version state
    Settings->>User: Display version in About section
    GitHubAPI-->>Settings: Error (if any)
    Settings->>User: Show error notification
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8f9fa11 and cbb4dc7.

📒 Files selected for processing (1)
  • Client/src/Pages/Settings/index.jsx (3 hunks)
🧰 Additional context used
🔇 Additional comments (4)
Client/src/Pages/Settings/index.jsx (4)

20-20: Yo, these imports are straight fire!

Bringin' in useState and useEffect like it's the last verse, that's what I'm talkin' about! These hooks are gonna make our component pop off the screen, no doubt.


40-40: Version state? That's the real MVP!

Yo, you just dropped that version state like it's hot! It's gonna hold our latest release info tighter than mom's spaghetti. Good stuff, homie!


323-323: Version display? That's the cherry on top, yo!

You're servin' up that version info like it's a fresh plate of mom's spaghetti. Users gonna eat this up! Keep that transparency flowin', it's all good in the hood.


331-332: New GitHub link? You're droppin' knowledge bombs!

Yo, you just upgraded that GitHub link like it's goin' platinum! Direct link to the repo? That's how we roll. Users gonna be all over this like vomit on a sweater. Keep it real, keep it accessible!

Client/src/Pages/Settings/index.jsx Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cbb4dc7 and 33dd78d.

📒 Files selected for processing (1)
  • Client/src/Pages/Settings/index.jsx (3 hunks)
🧰 Additional context used
🔇 Additional comments (4)
Client/src/Pages/Settings/index.jsx (4)

20-20: Yo, these imports are fresher than mom's spaghetti!

Adding useState and useEffect? That's the secret sauce we needed for this version-fetching feast. You're cookin' up some good React, homie!


40-40: Version state? That's the real MVP (Most Valuable Pasta)!

You're servin' up that version state like it's a hot plate of spaghetti. Keepin' it fresh and ready to update. That's how we roll in the React kitchen!


323-323: Version display? That's the cherry on top of mom's spaghetti!

You're servin' up that version info like it's the hottest dish in town. Users gonna eat this up faster than Eminem spits rhymes. Keep that info fresh and tasty!


331-332: This GitHub link? It's the real slim shady of URLs!

You've updated that link faster than Eminem changes his lyrics. Now users can dive straight into the code like they're diving into a bowl of mom's spaghetti. That's what I call a direct hit!

Client/src/Pages/Settings/index.jsx Outdated Show resolved Hide resolved
@gorkem-bwl
Copy link
Contributor

Fixes issue #967

I have added the tag which will fetch the latest version of the release from the github repo and show it in the about section of settings page.

Can you add a video of this?

@navishmonga
Copy link
Contributor Author

github-repo-version.mp4

Here it is

@gorkem-bwl
Copy link
Contributor

Looks good to me. What happens if GitHub is unreachable (e.g if the server is behind a firewall that blocks access)?

@navishmonga
Copy link
Contributor Author

navishmonga commented Oct 15, 2024

it will be blank in place of v1.1.0 and if any error occurs, it will show a notification when settings page loads
And also i am fetching the version number from github's api . So i don't think any fetching errors should until network goes down.

@gorkem-bwl
Copy link
Contributor

gorkem-bwl commented Oct 15, 2024

This is ok. Does the GitHub API require any tokens/keys etc?

@navishmonga
Copy link
Contributor Author

No just the url of the repository of which we want to fetch the version of

@gorkem-bwl
Copy link
Contributor

OK, thanks for the information.

Copy link
Collaborator

@ajhollid ajhollid left a comment

Choose a reason for hiding this comment

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

Nice work, looks good for the most part!

I think we can leverage a try/catch/finally flow here to make sure we always have a value for version.

We also use a NetworkService class to handle all of our network requests using Axios, please refactor the network request to make use of it.

Thanks for your contribution here, much appreciated!

try {
const response = await fetch(
"https://api.github.com/repos/bluewave-labs/bluewave-uptime/releases/latest"
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have a NetworkService class in which we use Axios to make all of our network requests. Can you refactor this to make use of the NetworkService so that all of our network requests are in one place?

@@ -37,10 +37,30 @@ const Settings = ({ isAdmin }) => {
const [form, setForm] = useState({
ttl: checkTTL ? (checkTTL / SECONDS_PER_DAY).toString() : 0,
});
const [version,setVersion]=useState("");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's provide a default value here in case network request fails, perhaps "unknown" for now is good.

setVersion(data.tag_name); // Set the latest version number
} catch (error) {
createToast({ body: error.message || "Error fetching latest version" }); // Set error message
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't we do this in case our network request fails:

let version = "unknown"
try {
   ...
   const data = await response.json()
   version = data.tag_name
} catch (error) {
    createToast(...)
} finally {
    setVersion(version)
}

Now we'll always have a recent value for version, even if it is unknown.

@navishmonga
Copy link
Contributor Author

I have made the requested changes. Can you please review it ?

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 33dd78d and 94e2876.

📒 Files selected for processing (2)
  • Client/src/Pages/Settings/index.jsx (3 hunks)
  • Client/src/Utils/NetworkService.js (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
Client/src/Pages/Settings/index.jsx (4)

20-20: Yo, these imports are fresh like mom's spaghetti!

The new imports are on point, bringin' in the heat we need for that version fetch. It's all good in the hood!


40-40: This state's so fresh, it's making my palms sweaty!

Yo, that 'version' state is comin' in hot with that "unknown" default. It's like you're reading my mind, dawg!


323-323: This About section's got more sauce than mom's spaghetti!

You're droppin' that version like it's hot, and that GitHub link's pointing straight to the source. It's all coming together like a perfect rhyme, you feel me?

Also applies to: 331-332


Line range hint 353-355: Props to you for those PropTypes, dawg!

You're laying down the law with those PropTypes like it's the last verse of the rap battle. That's some next-level code documentation right there!

Comment on lines +45 to +62
//Fetching latest release version from github
useEffect(() => {
const fetchLatestVersion = async () => {
let version="unknown";
try {
const response = await networkService.fetchGithubLatestRelease();
if (!response.status===200) {
throw new Error("Failed to fetch latest version");
}
version=response.data.tag_name;
} catch (error) {
createToast({ body: error.message || "Error fetching latest version" }); // Set error message
} finally{
setVersion(version);
}
};
fetchLatestVersion();
},[]);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

This useEffect's got more flow than Eminem, but there's a tiny hiccup!

Yo, this version fetch is tight like mom's spaghetti, using that networkService like a pro and handling errors smoother than a fresh beat. But peep this:

- if (!response.status===200) {
+ if (response.status !== 200) {

That condition's got a little stutter, you feel me? Fix that up and it'll be spittin' straight fire!

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
//Fetching latest release version from github
useEffect(() => {
const fetchLatestVersion = async () => {
let version="unknown";
try {
const response = await networkService.fetchGithubLatestRelease();
if (!response.status===200) {
throw new Error("Failed to fetch latest version");
}
version=response.data.tag_name;
} catch (error) {
createToast({ body: error.message || "Error fetching latest version" }); // Set error message
} finally{
setVersion(version);
}
};
fetchLatestVersion();
},[]);
//Fetching latest release version from github
useEffect(() => {
const fetchLatestVersion = async () => {
let version="unknown";
try {
const response = await networkService.fetchGithubLatestRelease();
if (response.status !== 200) {
throw new Error("Failed to fetch latest version");
}
version=response.data.tag_name;
} catch (error) {
createToast({ body: error.message || "Error fetching latest version" }); // Set error message
} finally{
setVersion(version);
}
};
fetchLatestVersion();
},[]);

Comment on lines +835 to +847

/**
* ************************************
* Fetcher github latest release version
* ************************************
*
* @async
* @returns {Promise<AxiosResponse>} The response from the axios GET request.
*
*/
async fetchGithubLatestRelease() {
return this.axiosInstance.get('https://api.github.com/repos/bluewave-labs/bluewave-uptime/releases/latest');
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Yo, this new method's got potential, but it's shakin' like mom's spaghetti!

The fetchGithubLatestRelease method is a solid addition, but it's got a few weak spots that might make your knees buckle:

  1. The URL's hardcoded like it's set in stone. What if we wanna check other repos? Let's make it flexible, ya feel me?
  2. There's no error handling, so if something goes wrong, it'll be like vomit on your sweater.
  3. We're hitting the GitHub API raw, no auth. That's gonna get us rate limited faster than you can say "Lose Yourself".

Here's how we can clean up this spaghetti:

- async fetchGithubLatestRelease() {
-   return this.axiosInstance.get('https://api.github.com/repos/bluewave-labs/bluewave-uptime/releases/latest');
- }
+ async fetchGithubLatestRelease(owner, repo, token = null) {
+   const url = `https://api.github.com/repos/${owner}/${repo}/releases/latest`;
+   const headers = token ? { Authorization: `token ${token}` } : {};
+   try {
+     return await this.axiosInstance.get(url, { headers });
+   } catch (error) {
+     logger.error(`Failed to fetch latest release for ${owner}/${repo}:`, error);
+     throw error;
+   }
+ }

This way, we're ready for whatever repo comes our way, we're handling errors like a pro, and we've got the option to use a token to avoid getting our palms all sweaty with rate limits. Now that's a recipe even mom would approve!

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* ************************************
* Fetcher github latest release version
* ************************************
*
* @async
* @returns {Promise<AxiosResponse>} The response from the axios GET request.
*
*/
async fetchGithubLatestRelease() {
return this.axiosInstance.get('https://api.github.com/repos/bluewave-labs/bluewave-uptime/releases/latest');
}
/**
* ************************************
* Fetcher github latest release version
* ************************************
*
* @async
* @param {string} owner - The owner of the repository
* @param {string} repo - The name of the repository
* @param {string} [token] - Optional GitHub API token for authentication
* @returns {Promise<AxiosResponse>} The response from the axios GET request.
*
*/
async fetchGithubLatestRelease(owner, repo, token = null) {
const url = `https://api.github.com/repos/${owner}/${repo}/releases/latest`;
const headers = token ? { Authorization: `token ${token}` } : {};
try {
return await this.axiosInstance.get(url, { headers });
} catch (error) {
logger.error(`Failed to fetch latest release for ${owner}/${repo}:`, error);
throw error;
}
}

Copy link
Collaborator

@ajhollid ajhollid left a comment

Choose a reason for hiding this comment

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

Looks good to me, we can remove the redundant version line and then we're good to go 👍

@@ -300,15 +320,16 @@ const Settings = ({ isAdmin }) => {
</Box>
<Box>
<Typography component="h2">BlueWave Uptime v1.0.0</Typography>
<Typography component="h2">Latest Version: {version}</Typography>
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need both of these, you can just combine them to

BlueWave Uptime: {version}

} catch (error) {
createToast({ body: error.message || "Error fetching latest version" }); // Set error message
} finally{
setVersion(version);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good to me!

@navishmonga
Copy link
Contributor Author

Done! Can you please check

Copy link
Collaborator

@ajhollid ajhollid left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for your hard work here!

@ajhollid ajhollid merged commit 4f9a53c into bluewave-labs:develop Oct 16, 2024
1 check was pending
@navishmonga navishmonga deleted the feature/github-repo-version branch October 25, 2024 13:42
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.

3 participants