Repository: hyperjumptech/monika
Pull request #1124 (2023-09-15 07:23:35)

Feat: adds a new flag to use the Symon API version
# Monika Pull Request (PR)

## What feature/issue does this PR add
1. Add a new flag `--symon-api-version` to use the Symon API version.

## How to test
1. Add `--symon-api-version` when running Monika with Symon mode.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/hyperjumptech/monika/pull/1124?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hyperjumptech) Report
> Merging [#1124](https://app.codecov.io/gh/hyperjumptech/monika/pull/1124?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hyperjumptech) (88b0673) into [main](https://app.codecov.io/gh/hyperjumptech/monika/commit/88b092df4958965721720131c7ff1538f2ed9601?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hyperjumptech) (88b092d) will **increase** coverage by `0.00%`.
> The diff coverage is `66.66%`.

> :exclamation: Current head 88b0673 differs from pull request most recent head f5a2f48. Consider uploading reports for the commit f5a2f48 to get more accurate results

```diff
@@           Coverage Diff           @@
##             main    #1124   +/-   ##
=======================================
  Coverage   60.43%   60.43%           
=======================================
  Files         113      113           
  Lines        3240     3243    +3     
  Branches      638      640    +2     
=======================================
+ Hits         1958     1960    +2     
  Misses       1002     1002           
- Partials      280      281    +1     
```


| [Files Changed](https://app.codecov.io/gh/hyperjumptech/monika/pull/1124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hyperjumptech) | Coverage Δ | |
|---|---|---|
| [src/context/monika-flags.ts](https://app.codecov.io/gh/hyperjumptech/monika/pull/1124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hyperjumptech#diff-c3JjL2NvbnRleHQvbW9uaWthLWZsYWdzLnRz) | `90.90% <ø> (ø)` | |
| [src/index.ts](https://app.codecov.io/gh/hyperjumptech/monika/pull/1124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hyperjumptech#diff-c3JjL2luZGV4LnRz) | `53.15% <ø> (ø)` | |
| [src/symon/index.ts](https://app.codecov.io/gh/hyperjumptech/monika/pull/1124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hyperjumptech#diff-c3JjL3N5bW9uL2luZGV4LnRz) | `68.08% <66.66%> (-0.04%)` | :arrow_down: |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hyperjumptech)


Patch:
diff --git a/src/context/monika-flags.ts b/src/context/monika-flags.ts
index ad6cf89e..17359703 100644
--- a/src/context/monika-flags.ts
+++ b/src/context/monika-flags.ts
@@ -57,6 +57,7 @@ export type MonikaFlags = {
   symonReportInterval?: number
   symonReportLimit?: number
   symonUrl?: string
+  'symon-api-version'?: string
   text?: string
   verbose: boolean
   version: void
diff --git a/src/index.ts b/src/index.ts
index ec3abbcd..88df9578 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -253,6 +253,13 @@ class Monika extends Command {
       description:
         'Monika will follow redirects as many times as the specified value here. By default, Monika will follow redirects once. To disable redirects following, set the value to zero.',
     }),
+
+    'symon-api-version': Flags.enum({
+      default: 'v1',
+      options: ['v1', 'v2'],
+      description:
+        'Symon API version to use. Available options: v1, v2. Default: v1',
+    }),
   }
 
   async run(): Promise<void> {
diff --git a/src/symon/index.ts b/src/symon/index.ts
index bbccda56..b280ccdd 100644
--- a/src/symon/index.ts
+++ b/src/symon/index.ts
@@ -168,8 +168,10 @@ class SymonClient {
     symonMonikaId,
     symonReportInterval,
     symonReportLimit,
+    'symon-api-version': apiVersion,
   }: Pick<
     MonikaFlags,
+    | 'symon-api-version'
     | 'symonUrl'
     | 'symonKey'
     | 'symonLocationId'
@@ -178,7 +180,7 @@ class SymonClient {
     | 'symonReportLimit'
   >) {
     this.httpClient = axios.create({
-      baseURL: `${symonUrl}/api/v1/monika`,
+      baseURL: `${symonUrl}/api/${apiVersion}/monika`,
       headers: {
         'x-api-key': symonKey,
       },


Test patch:
diff --git a/src/symon/index.test.ts b/src/symon/index.test.ts
index c5200851..749636a1 100644
--- a/src/symon/index.test.ts
+++ b/src/symon/index.test.ts
@@ -295,6 +295,7 @@ describe('Send incident or recovery event', () => {
     const symon = new SymonClient({
       symonUrl: 'http://localhost:4000',
       symonKey: 'abcd',
+      'symon-api-version': 'v1',
     })
     sinon.spy(symon, 'report')
     symon.monikaId = '1234'