Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@automa/bot

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@automa/bot - npm Package Compare versions

Comparing version 0.0.5 to 0.1.0

test/fixtures/download/README.md

10

package.json
{
"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": {

2

src/core.ts

@@ -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', () => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc