@automa/bot
Advanced tools
Comparing version 0.0.5 to 0.1.0
{ | ||
"name": "@automa/bot", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "Bot helpers for Automa", | ||
@@ -22,7 +22,5 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"@opentelemetry/api": "^1.8.0", | ||
"axios": "~1.7.4", | ||
"mkdirp": "~3.0.1", | ||
"rimraf": "~6.0.1", | ||
"tar": "~7.4.3" | ||
"tar": "~7.4.3", | ||
"zx": "~8.1.5" | ||
}, | ||
@@ -36,3 +34,3 @@ "scripts": { | ||
"engines": { | ||
"node": ">=22.3.0" | ||
"node": ">=20.17.0" | ||
}, | ||
@@ -39,0 +37,0 @@ "publishConfig": { |
@@ -49,3 +49,3 @@ import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios'; | ||
) { | ||
return axios< | ||
return axios.request< | ||
ResponseData, | ||
@@ -52,0 +52,0 @@ AxiosResponse<ResponseData, RequestData>, |
@@ -5,3 +5,3 @@ import * as Core from './core'; | ||
export { Code } from './resources'; | ||
export type { CodeDownloadParams } from './resources'; | ||
export type { CodeCleanupParams, CodeDownloadParams } from './resources'; | ||
@@ -8,0 +8,0 @@ export * from './webhook'; |
@@ -0,7 +1,7 @@ | ||
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises'; | ||
import { Readable } from 'node:stream'; | ||
import { pipeline } from 'node:stream/promises'; | ||
import { mkdirpSync } from 'mkdirp'; | ||
import { rimrafSync } from 'rimraf'; | ||
import { x as extract } from 'tar'; | ||
import { $ } from 'zx'; | ||
@@ -15,3 +15,14 @@ import * as Core from '../core'; | ||
/** | ||
* Cleans up the downloaded code for a task | ||
* @param body Task to cleanup code for | ||
*/ | ||
cleanup(body: CodeCleanupParams) { | ||
return rm(this.path(body.task), { recursive: true }); | ||
} | ||
/** | ||
* Downloads code for a task | ||
* @param body Task to download code for | ||
* @param options Request options | ||
* @returns Path to the downloaded code | ||
*/ | ||
@@ -35,15 +46,85 @@ async download( | ||
const folder = `/tmp/automa/tasks/${body.task.id}`; | ||
const folder = this.path(body.task); | ||
rimrafSync(folder); | ||
mkdirpSync(folder); | ||
await rm(folder, { recursive: true, force: true }); | ||
await mkdir(folder, { recursive: true }); | ||
await pipeline(response.data, extract({ cwd: folder })); | ||
// Save the proposal token for later use | ||
await writeFile( | ||
`${folder}/.git/automa_proposal_token`, | ||
response.headers['x-automa-proposal-token'], | ||
); | ||
return folder; | ||
} | ||
/** | ||
* Proposes code changes for a task | ||
* @param body Parameters for the code proposal | ||
* @param body.task Task to propose code changes for | ||
* @param body.proposal Proposal details | ||
* @param body.proposal.message Optional commit message for the proposal | ||
* @param options Request options | ||
* @returns Proposal that was created | ||
*/ | ||
async propose( | ||
body: CodeProposeParams, | ||
options?: Core.RequestOptions<CodeProposeRequestParams>, | ||
) { | ||
const folder = this.path(body.task); | ||
let token: string | undefined; | ||
try { | ||
// Read the proposal token from the downloaded code | ||
token = await readFile(`${folder}/.git/automa_proposal_token`, 'utf8'); | ||
} catch (e) {} | ||
if (!token) { | ||
throw new Error('Failed to read the stored proposal token'); | ||
} | ||
// TODO: Use programmatic git instead of system git | ||
const { stdout } = await $({ cwd: folder })`git diff`; | ||
return this._client.post<void, CodeProposeRequestParams>( | ||
'/code/propose', | ||
{ | ||
...body, | ||
proposal: { | ||
...body.proposal, | ||
token, | ||
diff: stdout, | ||
}, | ||
}, | ||
options, | ||
); | ||
} | ||
private path(task: Pick<Task, 'id'>) { | ||
return `/tmp/automa/tasks/${task.id}`; | ||
} | ||
} | ||
export interface CodeCleanupParams { | ||
task: Pick<Task, 'id'>; | ||
} | ||
export interface CodeDownloadParams { | ||
task: Pick<Task, 'id' | 'token'>; | ||
} | ||
interface CodeProposeRequestParams extends CodeDownloadParams { | ||
proposal: { | ||
token: string; | ||
diff: string; | ||
message?: string; | ||
}; | ||
} | ||
export interface CodeProposeParams extends CodeDownloadParams { | ||
proposal?: { | ||
message?: string; | ||
}; | ||
} |
import { assert } from 'chai'; | ||
import { verifyWebhook } from '../src/verify'; | ||
import { verifyWebhook } from '../src/webhook'; | ||
@@ -5,0 +5,0 @@ suite('verifyWebhook', () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
3
1
1
0
17506
13
540
1
+ Addedzx@~8.1.5
+ Added@types/fs-extra@11.0.4(transitive)
+ Added@types/jsonfile@6.1.4(transitive)
+ Added@types/node@22.10.5(transitive)
+ Addedundici-types@6.20.0(transitive)
+ Addedzx@8.1.9(transitive)
- Removed@opentelemetry/api@^1.8.0
- Removedmkdirp@~3.0.1
- Removedrimraf@~6.0.1
- Removed@opentelemetry/api@1.9.0(transitive)
- Removedglob@11.0.0(transitive)
- Removedjackspeak@4.0.2(transitive)
- Removedlru-cache@11.0.2(transitive)
- Removedminimatch@10.0.1(transitive)
- Removedpath-scurry@2.0.0(transitive)
- Removedrimraf@6.0.1(transitive)