Skip to content

Commit

Permalink
Handle promote on drafts path only
Browse files Browse the repository at this point in the history
  • Loading branch information
sukamat committed Nov 26, 2024
1 parent ee4da4f commit 95d1177
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
22 changes: 17 additions & 5 deletions tools/floodbox/crawl-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@
import RequestHandler from './request-handler.js';

class CrawlTree {
constructor(callback, accessToken, maxConcurrent = 500, crawlType = 'default', expName = '') {
constructor(callback, accessToken, maxConcurrent = 500, crawlType = 'default', expName = '', isDraftsOnly = false) {
this.queue = [];
this.activeCount = 0;
this.maxConcurrent = maxConcurrent;
this.callback = callback;
this.accessToken = accessToken;
this.crawlType = crawlType;
this.expName = expName;
this.isDraftsOnly = isDraftsOnly;

Check warning on line 19 in tools/floodbox/crawl-tree.js

View check run for this annotation

Codecov / codecov/patch

tools/floodbox/crawl-tree.js#L19

Added line #L19 was not covered by tests
this.requestHandler = new RequestHandler(this.accessToken);
// eslint-disable-next-line no-useless-escape
this.grayboxPathPattern = new RegExp(`^\/[^\/]+\/[^\/]+\/(?:[^\/]+\/)?${expName}(?:\/|$)`);
if (this.isDraftsOnly && this.crawlType === 'graybox') {
// eslint-disable-next-line no-useless-escape
this.grayboxPathPattern = new RegExp(`^\/[^\/]+\/[^\/]+\/(?:[^\/]+\/)?${expName}\/drafts(?:\/|$)`);
}

Check warning on line 26 in tools/floodbox/crawl-tree.js

View check run for this annotation

Codecov / codecov/patch

tools/floodbox/crawl-tree.js#L23-L26

Added lines #L23 - L26 were not covered by tests

this.push = this.push.bind(this);
this.processQueue = this.processQueue.bind(this);
Expand Down Expand Up @@ -57,8 +62,15 @@ class CrawlTree {
json.forEach((child) => {
if (!child.ext) {
folders.push(child.path);
} else if (this.crawlType !== 'graybox' || this.grayboxPathPattern.test(child.path)) {
files.push(child);
} else {
// Filter out files based on crawlType, grayboxPathPattern and isDraftsOnly flag
// eslint-disable-next-line no-lonely-if
if ((this.crawlType !== 'graybox' && this.crawlType !== 'floodgate')
|| (this.crawlType === 'graybox' && this.grayboxPathPattern.test(child.path))
|| (this.crawlType === 'floodgate' && (!this.isDraftsOnly || child.path.includes('/drafts/')))
) {
files.push(child);
}

Check warning on line 73 in tools/floodbox/crawl-tree.js

View check run for this annotation

Codecov / codecov/patch

tools/floodbox/crawl-tree.js#L65-L73

Added lines #L65 - L73 were not covered by tests
}
});
}
Expand All @@ -82,7 +94,7 @@ function calculateCrawlTime(startTime) {
* @param {string} options.crawlType - The type of crawl ('graybox' or other).
*/
function crawl({
path, callback, concurrent, throttle = 100, accessToken, crawlType = 'default',
path, callback, concurrent, throttle = 100, accessToken, crawlType = 'default', isDraftsOnly = false,

Check warning on line 97 in tools/floodbox/crawl-tree.js

View check run for this annotation

Codecov / codecov/patch

tools/floodbox/crawl-tree.js#L97

Added line #L97 was not covered by tests
}) {
let expName = '';
let sitePath = path;
Expand All @@ -98,7 +110,7 @@ function crawl({
const folders = [sitePath];
const inProgress = [];
const startTime = Date.now();
const queue = new CrawlTree(callback, accessToken, concurrent, crawlType, expName);
const queue = new CrawlTree(callback, accessToken, concurrent, crawlType, expName, isDraftsOnly);

Check warning on line 113 in tools/floodbox/crawl-tree.js

View check run for this annotation

Codecov / codecov/patch

tools/floodbox/crawl-tree.js#L113

Added line #L113 was not covered by tests

const results = new Promise((resolve) => {
const interval = setInterval(async () => {
Expand Down
1 change: 1 addition & 0 deletions tools/floodbox/floodgate/floodgate.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default class MiloFloodgate extends LitElement {
path: this._pinkSitePath,
accessToken: this.token,
crawlType: 'floodgate',
isDraftsOnly: this._floodgateConfig.isPromoteDraftsOnly,
callback: () => {
this.requestUpdate();
},
Expand Down
8 changes: 5 additions & 3 deletions tools/floodbox/graybox/graybox.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class MiloGraybox extends LitElement {
};
}

async startCrawl(experiencePath) {
async startCrawl(experiencePath, expName) {
const { results, getDuration } = crawl({
path: experiencePath,
callback: () => {
Expand All @@ -83,6 +83,7 @@ export default class MiloGraybox extends LitElement {
throttle: 10,
accessToken: this.token,
crawlType: 'graybox',
isDraftsOnly: this._grayboxConfig.isDraftsOnly(expName),
});
this._crawledFiles = await results;
this.cleanUpIgnoreFilesFromPromote(this._crawledFiles);
Expand All @@ -100,6 +101,7 @@ export default class MiloGraybox extends LitElement {
repo,
expName: exp,
promoteType: 'graybox',
isDraftOnly: this._grayboxConfig.isDraftsOnly(exp),
files: this._filesToPromote,
callback: (status) => {
// eslint-disable-next-line no-console
Expand Down Expand Up @@ -190,11 +192,11 @@ export default class MiloGraybox extends LitElement {
this.readPromoteIgnorePaths();

// #1 - Start crawling
const { org, repo, exp } = this.getOrgRepoExp();
this._startCrawlExp = true;
await this.startCrawl(this._gbExpPath);
await this.startCrawl(this._gbExpPath, exp);

// #2 - Start promoting
const { org, repo, exp } = this.getOrgRepoExp();
this._startPromote = true;
await this.startPromote(org, repo, exp);

Expand Down

0 comments on commit 95d1177

Please sign in to comment.