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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ght",
"version": "1.11.6",
"version": "1.11.7",
"scripts": {
"build": "tsc && cp package.json ght ./dist",
"dev": "NODE_ENV=development ts-node ./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ght
version: "1.11.6"
version: "1.11.7"
license: GPL-3.0
summary: Perform actions in Canonical's Greenhouse automatically.
description: An automated browser that does a set of tasks on Canonical's Greenhouse dashboard without the need of interaction with the UI.
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/Job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Config from "../config/Config";
jest.mock("../utils/pageUtils", () => ({
...jest.requireActual("../utils/pageUtils"),
getIDFromURL: jest.fn().mockReturnValue(1),
clearPopups: jest.fn(),
}));

const config = new Config();
Expand Down
9 changes: 9 additions & 0 deletions src/controllers/BaseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ export abstract class BaseController {
await this.screenRecorder.start();
}

await page.setRequestInterception(true);
page.on('request', request => {
if (request.url().includes('pendo.io')) {
request.abort();
} else {
request.continue();
}
});

return {
browser,
page,
Expand Down
9 changes: 9 additions & 0 deletions src/core/Job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { evaluate, isDevelopment } from "../utils/processUtils";
import Config from "../config/Config";
import { runPrompt } from "../utils/commandUtils";
import { clearPopups } from "../utils/pageUtils";
import * as Puppeteer from "puppeteer";
import { Ora } from "ora";
// @ts-ignore 2023-11-24: https://github.com/enquirer/enquirer/issues/135 still not solved.
Expand Down Expand Up @@ -125,9 +126,13 @@ export default class Job {
`/plans/${jobID}/jobapp`,
);
await this.page.goto(jobappURL);
await clearPopups(this.page);

const pageCount = await this.getPageCount();
for (let currentPage = 1; currentPage <= pageCount; currentPage++) {
await this.page.goto(`${jobappURL}?page=${currentPage}`);
await clearPopups(this.page);

job.posts.push(...(await this.getJobPosts(job)));
}
return job;
Expand Down Expand Up @@ -272,6 +277,7 @@ export default class Job {
public async getJobName(jobID: number): Promise<string> {
const url = joinURL(this.config.greenhouseUrl, `/plans/${jobID}`);
await this.page.goto(url);
await clearPopups(this.page);

const jobTitleElement = await this.page.$(".job-name");
const jobAnchor = await jobTitleElement?.$("a");
Expand All @@ -296,6 +302,7 @@ export default class Job {
`/alljobs/list?page=${page}`,
);
await this.page.goto(url);
await clearPopups(this.page);

const body = await this.page.$("body");
let innerHTML = await body?.evaluate((element) => element.innerHTML);
Expand Down Expand Up @@ -392,6 +399,8 @@ export default class Job {
`/jobapps/${postID}/edit`,
);
await this.page.goto(url);
await clearPopups(this.page);

const jobElement = await this.page.$(".job-name");
if (!jobElement) throw new Error(`Job cannot be found in ${url}.`);
return await getIDFromURL(jobElement, "a");
Expand Down
3 changes: 3 additions & 0 deletions src/core/JobPost.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { JobBoard, JobInfo, PostInfo } from "./types";
import { usaCities } from "../config/defaults";
import {
clearPopups,
getCSRFToken,
getIDFromURL,
getInnerText,
Expand Down Expand Up @@ -200,6 +201,7 @@ export default class JobPost {
`/jobapps/${jobPost.id}/edit`,
);
await this.page.goto(url1);
await clearPopups(this.page);

const element = await this.page.$("*[data-react-class='JobPostsForm']");
if (!element)
Expand Down Expand Up @@ -344,6 +346,7 @@ export default class JobPost {
`/plans/${jobPost.job.id}/jobapp`,
);
await this.page.goto(url);
await clearPopups(this.page);

const csrfToken = await getCSRFToken(this.page);
await sendRequest(
Expand Down
10 changes: 3 additions & 7 deletions src/core/LoadBalancer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Application, Grader, JobToAssign, GraderRecord } from "./types";
import { UserError } from "../utils/processUtils";
import { clearPopups } from "../utils/pageUtils";
import { green } from "colors";
import { Ora } from "ora";
import { Page } from "puppeteer";
Expand Down Expand Up @@ -289,13 +290,7 @@ export default class LoadBalancer {
for (const job of this.jobs) {
const url = this.buildUrl(job);
await this.page.goto(url, { waitUntil: "networkidle0" });

const cookiesOkButton = await this.page.$(
`#footer [data-provides="inform-cookies-popup"] button`,
);
if (cookiesOkButton) {
await cookiesOkButton.click();
}
await clearPopups(this.page);

await this.findUsername();
let page = 1;
Expand All @@ -321,6 +316,7 @@ export default class LoadBalancer {
await this.page.goto(url + `&page=${page}`, {
waitUntil: "networkidle0",
});
await clearPopups(this.page);
}
}
this.spinner.stop();
Expand Down
27 changes: 27 additions & 0 deletions src/utils/pageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,30 @@ export async function getIDFromURL(
const urlParts: string[] = url.split("/");
return parseInt(urlParts[urlParts.length - 1]);
}

export async function clearPopups(page) {
const cookiesOkButton = await page.$(
`#footer [data-provides="inform-cookies-popup"] button`,
);
if (cookiesOkButton) {
await cookiesOkButton.click();
}

// "join upcoming webinar popup"
// doesn't show up for everyone
const popupDismissButton = await page.$(
`button.bb-button._pendo-button-secondaryButton._pendo-button`,
);
if (popupDismissButton) {
await popupDismissButton.click();
}

// "join upcoming webinar popup"
// doesn't show up for everyone
const popupCloseButton = await page.$(
`button._pendo-close-guide`,
);
if (popupCloseButton) {
await popupCloseButton.click();
}
}