Skip to content

Commit

Permalink
chore: set AI PR description enabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Anush008 committed May 19, 2023
1 parent a5b7cdd commit bc0f4a9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/pages/aiprdescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
DescriptionLanguage,
setAIDescriptionConfig,
getDefaultDescriptionConfig,
setDefaultDescriptionConfig,
toggleAIPRDescriptionEnabled,
} from "../utils/aiprdescription/descriptionconfig";
import { useRefs } from "../hooks/useRefs";
import { configurationReducer } from "../utils/aiprdescription/configurationReducer";
Expand Down Expand Up @@ -85,12 +85,12 @@ const AIPRDescription = () => {
}`}
onClick={() => {
setFormDisabled(!formDisabled);
dispatch({ type: "CLEAR", value: null });
dispatch({ type: "TOGGLE_ENABLED", value: config });
void toggleAIPRDescriptionEnabled();
if (formDisabled) {
toast.success("AI PR Description enabled!");
} else {
toast.success("AI PR Description enabled!");
} else {
toast.error("AI PR Description disabled!");
setDefaultDescriptionConfig();
}
}}
>
Expand Down
3 changes: 3 additions & 0 deletions src/utils/aiprdescription/configurationReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export const configurationReducer = (state: DescriptionConfig, action: { type: s
case "SET_TONE":
newState.config.tone = action.value;
break;
case "TOGGLE_ENABLED":
newState.enabled = !newState.enabled;
break;
case "CLEAR":
newState = getDefaultDescriptionConfig();
break;
Expand Down
30 changes: 20 additions & 10 deletions src/utils/aiprdescription/descriptionconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,29 @@ export const setAIDescriptionConfig = async (data: DescriptionConfig): Promise<v
};

export const getDefaultDescriptionConfig = (): DescriptionConfig => ({
enabled: false,
config: {
length: 500,
maxInputLength: 3900,
temperature: 7,
language: "english",
tone: "informative",
source: "diff",
},
});
enabled: true,
config: {
length: 500,
maxInputLength: 3900,
temperature: 7,
language: "english",
tone: "informative",
source: "diff",
},
});

export const setDefaultDescriptionConfig = () => {
const defaultConfig = getDefaultDescriptionConfig();

void setAIDescriptionConfig(defaultConfig);
};

export const toggleAIPRDescriptionEnabled = async () => {
const config = await getAIDescriptionConfig();

if (typeof config?.enabled === "undefined") return;
config.enabled = !config.enabled;
await setAIDescriptionConfig(config);

return;
}

0 comments on commit bc0f4a9

Please sign in to comment.