Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Deva309 committed Nov 4, 2024
2 parents 8cb4ff3 + d809cd5 commit 74ea5e8
Show file tree
Hide file tree
Showing 285 changed files with 20,394 additions and 14,046 deletions.
1 change: 1 addition & 0 deletions .github/workflows/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,5 @@ module.exports = {
slackNotification,
pulls: { addLabels, addFiles, getChecks, getReviews },
isWithinRCP,
RCPDates,
};
91 changes: 45 additions & 46 deletions .github/workflows/merge-to-stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const {
// Run from the root of the project for local testing: node --env-file=.env .github/workflows/merge-to-stage.js
const PR_TITLE = '[Release] Stage to Main';
const SEEN = {};
const REQUIRED_APPROVALS = process.env.REQUIRED_APPROVALS || 2;
const REQUIRED_APPROVALS = process.env.REQUIRED_APPROVALS ? Number(process.env.REQUIRED_APPROVALS) : 2;
const MAX_MERGES = process.env.MAX_PRS_PER_BATCH ? Number(process.env.MAX_PRS_PER_BATCH) : 8;
let existingPRCount = 0;
const STAGE = 'stage';
const PROD = 'main';
const LABELS = {
Expand All @@ -25,13 +27,13 @@ const TEAM_MENTIONS = [
'@adobecom/document-cloud-sot',
];
const SLACK = {
merge: ({ html_url, number, title, prefix = '' }) =>
`:merged: PR merged to stage: ${prefix} <${html_url}|${number}: ${title}>.`,
openedSyncPr: ({ html_url, number }) =>
`:fast_forward: Created <${html_url}|Stage to Main PR ${number}>`,
merge: ({ html_url, number, title, prefix = '' }) => `:merged: PR merged to stage: ${prefix} <${html_url}|${number}: ${title}>.`,
openedSyncPr: ({ html_url, number }) => `:fast_forward: Created <${html_url}|Stage to Main PR ${number}>`,
};

let github, owner, repo;
let github;
let owner;
let repo;

let body = `
## common base root URLs
Expand All @@ -49,11 +51,7 @@ let body = `
const isHighPrio = (labels) => labels.includes(LABELS.highPriority);
const isZeroImpact = (labels) => labels.includes(LABELS.zeroImpact);

const hasFailingChecks = (checks) =>
checks.some(
({ conclusion, name }) =>
name !== 'merge-to-stage' && conclusion === 'failure'
);
const hasFailingChecks = (checks) => checks.some(({ conclusion, name }) => name !== 'merge-to-stage' && conclusion === 'failure');

const commentOnPR = async (comment, prNumber) => {
console.log(comment); // Logs for debugging the action.
Expand Down Expand Up @@ -91,18 +89,15 @@ const getPRs = async () => {

prs = prs.filter(({ checks, reviews, number, title }) => {
if (hasFailingChecks(checks)) {
commentOnPR(
`Skipped merging ${number}: ${title} due to failing checks`,
number
);
commentOnPR(`Skipped merging ${number}: ${title} due to failing checks`, number);
return false;
}

const approvals = reviews.filter(({ state }) => state === 'APPROVED');
if (approvals.length < REQUIRED_APPROVALS) {
commentOnPR(
`Skipped merging ${number}: ${title} due to insufficient approvals. Required: ${REQUIRED_APPROVALS} approvals`,
number
number,
);
return false;
}
Expand All @@ -121,7 +116,7 @@ const getPRs = async () => {
}
return categorizedPRs;
},
{ zeroImpactPRs: [], highImpactPRs: [], normalPRs: [] }
{ zeroImpactPRs: [], highImpactPRs: [], normalPRs: [] },
);
};

Expand All @@ -130,11 +125,12 @@ const merge = async ({ prs, type }) => {

for await (const { number, files, html_url, title } of prs) {
try {
if (mergeLimitExceeded()) return;
const fileOverlap = files.find((file) => SEEN[file]);
if (fileOverlap) {
commentOnPR(
`Skipped ${number}: "${title}" due to file "${fileOverlap}" overlap. Merging will be attempted in the next batch`,
number
number,
);
continue;
}
Expand All @@ -150,6 +146,8 @@ const merge = async ({ prs, type }) => {
merge_method: 'squash',
});
}
existingPRCount++;
console.log(`Current number of PRs merged: ${existingPRCount}`);
const prefix = type === LABELS.zeroImpact ? ' [ZERO IMPACT]' : '';
body = `-${prefix} ${html_url}\n${body}`;
await slackNotification(
Expand All @@ -158,26 +156,25 @@ const merge = async ({ prs, type }) => {
number,
title,
prefix,
})
}),
).catch(console.error);
await new Promise((resolve) => setTimeout(resolve, 5000));
} catch (error) {
files.forEach((file) => (SEEN[file] = false));
commentOnPR(`Error merging ${number}: ${title} ` + error.message, number);
commentOnPR(`Error merging ${number}: ${title} ${error.message}`, number);
}
}
};

const getStageToMainPR = () =>
github.rest.pulls
.list({ owner, repo, state: 'open', base: PROD })
.then(({ data } = {}) => data.find(({ title } = {}) => title === PR_TITLE))
.then((pr) => pr && addLabels({ pr, github, owner, repo }))
.then((pr) => pr && addFiles({ pr, github, owner, repo }))
.then((pr) => {
pr?.files.forEach((file) => (SEEN[file] = true));
return pr;
});
const getStageToMainPR = () => github.rest.pulls
.list({ owner, repo, state: 'open', base: PROD })
.then(({ data } = {}) => data.find(({ title } = {}) => title === PR_TITLE))
.then((pr) => pr && addLabels({ pr, github, owner, repo }))
.then((pr) => pr && addFiles({ pr, github, owner, repo }))
.then((pr) => {
pr?.files.forEach((file) => (SEEN[file] = true));
return pr;
});

const openStageToMainPR = async () => {
const { data: comparisonData } = await github.rest.repos.compareCommits({
Expand All @@ -188,22 +185,19 @@ const openStageToMainPR = async () => {
});

for (const commit of comparisonData.commits) {
const { data: pullRequestData } =
await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner,
repo,
commit_sha: commit.sha,
});
const { data: pullRequestData } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner,
repo,
commit_sha: commit.sha,
});

for (const pr of pullRequestData) {
if (!body.includes(pr.html_url)) body = `- ${pr.html_url}\n${body}`;
}
}

try {
const {
data: { html_url, number },
} = await github.rest.pulls.create({
const { data: { html_url, number } } = await github.rest.pulls.create({
owner,
repo,
title: PR_TITLE,
Expand All @@ -222,29 +216,34 @@ const openStageToMainPR = async () => {
await slackNotification(SLACK.openedSyncPr({ html_url, number }));
await slackNotification(
SLACK.openedSyncPr({ html_url, number }),
process.env.MILO_STAGE_SLACK_WH
process.env.MILO_STAGE_SLACK_WH,
);
} catch (error) {
if (error.message.includes('No commits between main and stage'))
return console.log('No new commits, no stage->main PR opened');
if (error.message.includes('No commits between main and stage')) return console.log('No new commits, no stage->main PR opened');
throw error;
}
};

const mergeLimitExceeded = () => MAX_MERGES - existingPRCount < 0;

const main = async (params) => {
github = params.github;
owner = params.context.repo.owner;
repo = params.context.repo.repo;
if (isWithinRCP(2)) return console.log('Stopped, within RCP period.');
if (isWithinRCP(process.env.STAGE_RCP_OFFSET_DAYS || 2)) return console.log('Stopped, within RCP period.');

try {
const stageToMainPR = await getStageToMainPR();
console.log('has Stage to Main PR:', !!stageToMainPR);
if (stageToMainPR) body = stageToMainPR.body;
existingPRCount = body.match(/https:\/\/github\.com\/adobecom\/milo\/pull\/\d+/g)?.length || 0;
console.log(`Number of PRs already in the batch: ${existingPRCount}`);

if (mergeLimitExceeded()) return console.log(`Maximum number of '${MAX_MERGES}' PRs already merged. Stopping execution`);

const { zeroImpactPRs, highImpactPRs, normalPRs } = await getPRs();
await merge({ prs: zeroImpactPRs, type: LABELS.zeroImpact });
if (stageToMainPR?.labels.some((label) => label.includes(LABELS.SOTPrefix)))
return console.log('PR exists & testing started. Stopping execution.');
if (stageToMainPR?.labels.some((label) => label.includes(LABELS.SOTPrefix))) return console.log('PR exists & testing started. Stopping execution.');
await merge({ prs: highImpactPRs, type: LABELS.highPriority });
await merge({ prs: normalPRs, type: 'normal' });
if (!stageToMainPR) await openStageToMainPR();
Expand All @@ -254,7 +253,7 @@ const main = async (params) => {
owner,
repo,
pull_number: stageToMainPR.number,
body: body,
body,
});
}
console.log('Process successfully executed.');
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/merge-to-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ env:
REQUIRED_APPROVALS: ${{ secrets.REQUIRED_APPROVALS }}
SLACK_HIGH_IMPACT_PR_WEBHOOK: ${{ secrets.SLACK_HIGH_IMPACT_PR_WEBHOOK }}
MILO_STAGE_SLACK_WH: ${{secrets.MILO_STAGE_SLACK_WH}}
MAX_PRS_PER_BATCH: ${{secrets.MAX_PRS_PER_BATCH}}
STAGE_RCP_OFFSET_DAYS: ${{secrets.STAGE_RCP_OFFSET_DAYS}}

jobs:
merge-to-stage:
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/rcp-notifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const {
slackNotification,
getLocalConfigs,
RCPDates,
} = require('./helpers.js');

const isWithin24Hours = (targetDate) =>
Math.abs(new Date() - targetDate) <= 24 * 60 * 60 * 1000;

const calculateDateOffset = (date, offset) => {
const newDate = new Date(date);
newDate.setDate(newDate.getDate() - offset);
return newDate;
};

// Run from the root of the project for local testing: node --env-file=.env .github/workflows/rcp-notifier.js
const main = async () => {
console.log('Action: RCP Notifier started');
for (const rcp of RCPDates) {
const start = new Date(rcp.start);
const end = new Date(rcp.end);
const tenDaysBefore = calculateDateOffset(start, 10);
const fourDaysBefore = calculateDateOffset(start, 4);
const stageOffset = Number(process.env.STAGE_RCP_OFFSET_DAYS) || 2;
const slackText = (days) =>
`Reminder RCP starts in ${days} days: from ${start.toUTCString()} to ${end.toUTCString()}. Merges to stage will be disabled beginning ${calculateDateOffset(start, stageOffset).toUTCString()}.`;
if (isWithin24Hours(tenDaysBefore)) {
console.log('Is within 24 hours of 10 days before RCP');
await slackNotification(slackText(10), process.env.MILO_DEV_HOOK);
}

if (isWithin24Hours(fourDaysBefore)) {
console.log('Is within 24 hours of 4 days before RCP');
await slackNotification(slackText(4), process.env.MILO_DEV_HOOK);
}
}

console.log('Action: RCP Notifier completed');
};

if (process.env.LOCAL_RUN) {
const { context } = getLocalConfigs();
main({ context });
}

module.exports = main;
24 changes: 24 additions & 0 deletions .github/workflows/rcp-notifier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: RCP Notifier

on:
schedule:
- cron: '43 9 * * *' # 9.43am UTC

env:
STAGE_RCP_OFFSET_DAYS: ${{ secrets.STAGE_RCP_OFFSET_DAYS }}
MILO_DEV_HOOK: ${{ secrets.MILO_DEV_HOOK }}

jobs:
rcp-notification:
if: github.repository_owner == 'adobecom'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Create RCP Notification
uses: actions/github-script@v7
with:
script: |
const main = require('./.github/workflows/rcp-notifier.js')
main({ github, context })
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ logs/*
**/mas/*/stats.json
test-html-results/
test-results/
test-a11y-results/
5 changes: 0 additions & 5 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@
# See https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners

# Milo Core (alphabetical order)
/fstab.yaml @adobecom/admins
/libs/features/ @adobecom/admins
/libs/features/seotech/ @hparra
/libs/features/title-append/ @hparra
/libs/martech/ @adobecom/admins
/libs/scripts/ @adobecom/admins
/libs/scripts/taxonomy.js @meganthecoder @JasonHowellSlavin @Brandon32 @rgclayton
/libs/utils/ @adobecom/admins

# Milo Blocks (alphabetical order)
/libs/blocks/accordion/ @fullcolorcoder @ryanmparrish
Expand Down
1 change: 0 additions & 1 deletion libs/blocks/article-feed/article-feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ async function buildFilter(type, tax, block, config) {
applyBtn.classList.add('button', 'small', 'apply');
applyBtn.textContent = await replacePlaceholder('apply');
applyBtn.addEventListener('click', () => {
// sampleRUM('apply-topic-filter');
delete config.selectedProducts;
delete config.selectedIndustries;
closeCurtain();
Expand Down
4 changes: 4 additions & 0 deletions libs/blocks/article-header/article-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,24 @@ async function buildSharing() {
twitter: {
'data-href': `https://www.twitter.com/share?&url=${url}&text=${title}`,
'aria-label': 'share twitter',
tabindex: '0',
},
linkedin: {
'data-type': 'LinkedIn',
'data-href': `https://www.linkedin.com/shareArticle?mini=true&url=${url}&title=${title}&summary=${description || ''}`,
'aria-label': 'share linkedin',
tabindex: '0',
},
facebook: {
'data-type': 'Facebook',
'data-href': `https://www.facebook.com/sharer/sharer.php?u=${url}`,
'aria-label': 'share facebook',
tabindex: '0',
},
link: {
id: 'copy-to-clipboard',
'aria-label': 'copy to clipboard',
tabindex: '0',
},
};

Expand Down
6 changes: 3 additions & 3 deletions libs/blocks/bulk-publish-v2/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const setUserData = (event) => {

const isPushedDown = async () => {
const callback = () => {
const sidekick = document.querySelector('helix-sidekick');
const sidekick = document.querySelector('aem-sidekick, helix-sidekick');
const pushdown = sidekick?.getAttribute('pushdown');
const bulkPub = document.querySelector('.bulk-publish-v2');
if (pushdown && !bulkPub.classList.contains('pushdown')) {
Expand All @@ -81,13 +81,13 @@ const isPushedDown = async () => {
const authenticate = async (tool = null) => {
isPushedDown();
const setUser = (event) => { tool.user = setUserData(event); };
const openSideKick = document.querySelector('helix-sidekick');
const openSideKick = document.querySelector('aem-sidekick, helix-sidekick');
if (openSideKick) {
openSideKick.addEventListener('statusfetched', setUser);
/* c8 ignore next 6 */
} else {
document.addEventListener('sidekick-ready', () => {
const sidekick = document.querySelector('helix-sidekick');
const sidekick = document.querySelector('aem-sidekick, helix-sidekick');
sidekick.addEventListener('statusfetched', setUser);
}, { once: true });
}
Expand Down
Loading

0 comments on commit 74ea5e8

Please sign in to comment.