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

feature request: telling user when new version is available #35

Merged
merged 7 commits into from
Mar 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opencommit",
"version": "1.1.11",
Copy link
Contributor

Choose a reason for hiding this comment

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

@nader-zouaoui the current version is already 1.1.16. Is your branch up to date?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the computed changes after the merge, so yeah it will be up-to-date after this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Copy link
Contributor

Choose a reason for hiding this comment

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

I understood!
Per the Contribution Guidelines the pull request must be opened to the master branch. That's why I got confused.

Copy link
Contributor

@openefit openefit Mar 18, 2023

Choose a reason for hiding this comment

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

I think Contribution Guidelines should be updated, and the default should be the dev branch.

"version": "1.1.16",
"description": "GPT CLI to auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
"keywords": [
"git",
19 changes: 18 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
@@ -53,7 +53,10 @@ class OpenAi {
} catch (error: unknown) {
outro(`${chalk.red('✖')} ${error}`);

if (axios.isAxiosError<{ error?: { message: string } }>(error) && error.response?.status === 401) {
if (
axios.isAxiosError<{ error?: { message: string } }>(error) &&
error.response?.status === 401
) {
const openAiError = error.response.data.error;

if (openAiError?.message) outro(openAiError.message);
@@ -67,4 +70,18 @@ class OpenAi {
};
}

export const getOpenCommitLatestVersion = async (): Promise<
string | undefined
> => {
try {
const { data } = await axios.get(
'https://unpkg.com/opencommit/package.json'
);
return data.version;
} catch (_) {
outro('Error while getting the latest version of opencommit');
return undefined;
}
};

export const api = new OpenAi();
4 changes: 3 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import { configCommand } from './commands/config';
import { hookCommand, isHookCalled } from './commands/githook.js';
import { prepareCommitMessageHook } from './commands/prepare-commit-msg-hook';
import { commit } from './commands/commit';
import { checkIsLatestVersion } from './utils/checkIsLatestVersion';

const rawArgv = process.argv.slice(2);

@@ -19,7 +20,8 @@ cli(
ignoreArgv: (type) => type === 'unknown-flag' || type === 'argument',
help: { description: packageJSON.description }
},
() => {
async () => {
await checkIsLatestVersion();
if (isHookCalled) {
prepareCommitMessageHook();
} else {
24 changes: 24 additions & 0 deletions src/utils/checkIsLatestVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { getOpenCommitLatestVersion } from '../api';
import currentPackage from '../../package.json' assert { type: 'json' };
import chalk from 'chalk';
export const checkIsLatestVersion = async () => {
const latestVersion = await getOpenCommitLatestVersion();

if (latestVersion) {
const currentVersion = currentPackage.version;

if (currentVersion !== latestVersion) {
console.warn(
chalk.yellow(
Copy link
Contributor

Choose a reason for hiding this comment

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

@nader-zouaoui What do you think about already suggesting the command to perform the update? ex:

🎉 Update to latest version by running: npm update opencommit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, will do it

`
You are not using the latest stable version of OpenCommit!
Consider updating to the latest version to get the latest features and bug fixes.
Current version: ${currentVersion}
Latest version: ${latestVersion}
🎉 To update to the latest version, run: npm update opencommit
Copy link
Contributor Author

Choose a reason for hiding this comment

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

`
)
);
}
}
};