Skip to content

Commit

Permalink
Merge pull request #20 from whck6/feature/bot-strings-language-locali…
Browse files Browse the repository at this point in the history
…zation

feat: add a new parmater
  • Loading branch information
rndquu authored Sep 6, 2024
2 parents 7f66809 + fb4298e commit 7e17676
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ plugins:
with:
# Define configurable items here and the kernel will pass these to the plugin.
configurableResponse: "Hello, is it me you are looking for?"
customStringsUrl: "https://raw.githubusercontent.com/ubiquibot/plugin-template/development/strings.json"
```
###### At this stage, your plugin will fire on your defined events with the required settings passed in from the kernel. You can now start writing your plugin's logic.
Expand Down
11 changes: 10 additions & 1 deletion src/handlers/hello-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function helloWorld(context: Context) {
logger,
payload,
octokit,
config: { configurableResponse },
config: { configurableResponse, customStringsUrl },
} = context;

const sender = payload.comment.user?.login;
Expand All @@ -39,6 +39,15 @@ export async function helloWorld(context: Context) {
issue_number: payload.issue.number,
body: configurableResponse,
});
if (customStringsUrl) {
const response = await fetch(customStringsUrl).then((value) => value.json());
await octokit.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue.number,
body: response.greeting,
});
}
} catch (error) {
/**
* logger.fatal should not be used in 9/10 cases. Use logger.error instead.
Expand Down
1 change: 1 addition & 0 deletions src/types/plugin-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface PluginInputs<T extends SupportedEventsU = SupportedEventsU, TU
export const pluginSettingsSchema = T.Object(
{
configurableResponse: T.String(),
customStringsUrl: T.Optional(T.String()),
},
{ default: { configurableResponse: "Hello, world!" } }
);
Expand Down
4 changes: 4 additions & 0 deletions strings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"greeting": "Hello user",
"taskAssignment": "You've been assigned to the task"
}

0 comments on commit 7e17676

Please sign in to comment.