Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions components/browserless/actions/take-screenshot/take-screenshot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import puppeteer from "puppeteer-core";
export default {
key: "browserless-take-screenshot",
name: "Take a Screenshot",
version: "0.5.1",
version: "0.5.3",
type: "action",
props: {
browserless: {
Expand All @@ -16,16 +16,29 @@ export default {
label: "URL",
description: "Enter the URL you'd like to take a screenshot of here",
},
screenshotOptions: {
type: "object",
label: "Screenshot Options",
optional: true,
description: "Pass options directly to the `Page.screenshot()` method. [Full list available here](https://puppeteer.github.io/puppeteer/docs/9.1.1/puppeteer.page.screenshot/)."
},
viewportOptions: {
type: "object",
label: "Viewport Options",
optional: true,
description: "Set the browsers viewport options. Passed to the `page.setViewport()` method."
}
},
async run({ $ }) {
const browser = await puppeteer.connect({
browserWSEndpoint: `wss://chrome.browserless.io?token=${this.browserless.$auth.api_key}`,
});
const page = await browser.newPage();
page.setViewport(this.viewportOptions)

const { url } = this;
await page.goto(url);
const screenshot = await page.screenshot();
const screenshot = await page.screenshot(this.screenshotOptions ?? {});

// export the base64-encoded screenshot for use in future steps,
// along with the image type and filename
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import gitlab from "../../gitlab.app.mjs";

export default {
name: "Create New Merge Request Thread",
version: "0.0.1",
key: "create-new-merge-request-thread",
description: "Create a new thread on a Merge Request",
props: {
gitlab,
projectId: {
propDefinition: [
gitlab,
"projectId",
],
},
mergeRequestIid: {
type: "integer",
label: "Merge Request ID",
description: "The ID of the Merge Request (integer)"
},
body: {
type: "string",
label: "Body",
description: "The body of the comment on the new thread. Markdown is supported."
}
},
type: "action",
methods: {},
async run({ $ }) {
const { data } = await this.gitlab.createNewMergeRequestThread(this.projectId, this.mergeRequestIid, { body: this.body });
return data;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import gitlab from "../../gitlab.app.mjs";

export default {
name: "Upload Project File",
version: "0.0.1",
key: "upload-project-file",
description: "Upload a file to a project",
props: {
gitlab,
projectId: {
propDefinition: [
gitlab,
"projectId",
],
},
file: {
type: "string",
label: "File to upload",
description: "A valid base64 encoded string representing the file"
},
fileName: {
type: "string",
label: "The name of the file",
description: "Example: image.png if an PNG image is passed to the `file` prop"
}
},
type: "action",
methods: {},
async run({ $ }) {
const { data } = await this.gitlab.uploadFile(this.projectId, this.file, this.fileName)

return data;
},
};
23 changes: 23 additions & 0 deletions components/gitlab/gitlab.app.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Gitlab } from "@gitbeaker/node";
import axios from 'axios';
import FormData from 'form-data';
import constants from "./common/constants.mjs";
import { v4 } from "uuid";

Expand Down Expand Up @@ -314,5 +316,26 @@ export default {
}
return api.all(params);
},
async uploadFile(projectId, file, fileName) {
// Read file as a Buffer
const image = Buffer.from(file, "base64");
// Create a form and append image with additional fields
const form = new FormData();
form.append('file', image, fileName);

return axios.post(`https://gitlab.com/api/v4/projects/${projectId}/uploads`, form, {
headers: {
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
"Content-Type": "multipart/form-data"
}
})
},
async createNewMergeRequestThread(projectId, mergeRequestIid, opts = {}) {
return axios.post(`https://gitlab.com/api/v4/projects/${projectId}/merge_requests/${mergeRequestIid}/discussions`, opts, {
headers: {
Authorization: `Bearer ${this.$auth.oauth_access_token}`
}
})
}
},
};