Skip to content
Merged
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
163 changes: 82 additions & 81 deletions .github/upload-preview.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,98 @@
const fs = require('fs');
const path = require('path');
const { Octokit } = require('@octokit/rest');
const octokit = new Octokit({ auth: process.env.GH_PR_TOKEN });
const surge = require('surge');
const publishFn = surge().publish();

// From github actions
const ghrepo = process.env.GITHUB_REPOSITORY || '';
(async () => {
const { Octokit } = await import('@octokit/rest');
const octokit = new Octokit({ auth: process.env.GH_PR_TOKEN });

const owner = process.env.CIRCLE_PROJECT_USERNAME || ghrepo.split('/')[0]; // patternfly
const repo = process.env.CIRCLE_PROJECT_REPONAME || ghrepo.split('/')[1];
const prnum = process.env.CIRCLE_PR_NUMBER || process.env.GH_PR_NUM;
const prbranch = process.env.CIRCLE_BRANCH || process.env.GITHUB_REF.split('/').pop();
// From github actions
const ghrepo = process.env.GITHUB_REPOSITORY || '';

const uploadFolder = process.argv[2];
if (!uploadFolder) {
console.log('Usage: upload-preview uploadFolder');
process.exit(1);
}
const owner = process.env.CIRCLE_PROJECT_USERNAME || ghrepo.split('/')[0]; // patternfly
const repo = process.env.CIRCLE_PROJECT_REPONAME || ghrepo.split('/')[1];
const prnum = process.env.CIRCLE_PR_NUMBER || process.env.GH_PR_NUM;
const prbranch = process.env.CIRCLE_BRANCH || process.env.GITHUB_REF.split('/').pop();

const uploadFolderName = path.basename(uploadFolder);
let uploadURL = `${repo}-${prnum ? `pr-component-groups-${prnum}` : prbranch}`.replace(/[\/|\.]/g, '-');
const uploadFolder = process.argv[2];
if (!uploadFolder) {
console.log('Usage: upload-preview uploadFolder');
process.exit(1);
}

switch(uploadFolderName) {
case 'coverage':
uploadURL += '-a11y.surge.sh';
break;
case 'public':
if (!prnum && prbranch === 'main') {
uploadURL = 'https://pf-extensions.surge.sh/';
}
else {
const uploadFolderName = path.basename(uploadFolder);
let uploadURL = `${repo}-${prnum ? `pr-component-groups-${prnum}` : prbranch}`.replace(/[\/|\.]/g, '-');

switch(uploadFolderName) {
case 'coverage':
uploadURL += '-a11y.surge.sh';
break;
case 'public':
if (!prnum && prbranch === 'main') {
uploadURL = 'https://pf-extensions.surge.sh/';
} else {
uploadURL += '.surge.sh';
}
break;
default:
uploadURL += `-${uploadFolderName}`;
uploadURL += '.surge.sh';
}
break;
default:
uploadURL += `-${uploadFolderName}`;
uploadURL += '.surge.sh';
break;
}
break;
}

publishFn({
project: uploadFolder,
p: uploadFolder,
domain: uploadURL,
d: uploadURL,
e: 'https://surge.surge.sh',
endpoint: 'https://surge.surge.sh'
});
publishFn({
project: uploadFolder,
p: uploadFolder,
domain: uploadURL,
d: uploadURL,
e: 'https://surge.surge.sh',
endpoint: 'https://surge.surge.sh'
});

function tryAddComment(comment, commentBody) {
if (!commentBody.includes(comment)) {
return comment;
function tryAddComment(comment, commentBody) {
if (!commentBody.includes(comment)) {
return comment;
}
return '';
}
return '';
}

if (prnum) {
octokit.issues.listComments({
owner,
repo,
issue_number: prnum
})
.then(res => res.data)
.then(comments => {
let commentBody = '';
const existingComment = comments.find(comment => comment.user.login === 'patternfly-build');
if (existingComment) {
commentBody += existingComment.body.trim();
commentBody += '\n\n';
}
if (prnum) {
const comments = await octokit.issues.listComments({
owner,
repo,
issue_number: prnum
}).then(res => res.data);

if (uploadFolderName === 'public') {
commentBody += tryAddComment(`Preview: https://${uploadURL}`, commentBody);
}
else if (uploadFolderName === 'coverage') {
commentBody += tryAddComment(`A11y report: https://${uploadURL}`, commentBody);
}
let commentBody = '';
const existingComment = comments.find(comment => comment.user.login === 'patternfly-build');
if (existingComment) {
commentBody += existingComment.body.trim();
commentBody += '\n\n';
}

if (existingComment) {
octokit.issues.updateComment({
owner,
repo,
comment_id: existingComment.id,
body: commentBody
}).then(() => console.log('Updated comment!'));
} else {
octokit.issues.createComment({
owner,
repo,
issue_number: prnum,
body: commentBody
}).then(() => console.log('Created comment!'));
}
});
}
if (uploadFolderName === 'public') {
commentBody += tryAddComment(`Preview: https://${uploadURL}`, commentBody);
} else if (uploadFolderName === 'coverage') {
commentBody += tryAddComment(`A11y report: https://${uploadURL}`, commentBody);
}

if (existingComment) {
await octokit.issues.updateComment({
owner,
repo,
comment_id: existingComment.id,
body: commentBody
});
console.log('Updated comment!');
} else {
await octokit.issues.createComment({
owner,
repo,
issue_number: prnum,
body: commentBody
});
console.log('Created comment!');
}
}
})();
40 changes: 0 additions & 40 deletions config/setupTests.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,3 @@
/* eslint-disable no-unused-vars */
import 'whatwg-fetch';
import 'babel-polyfill';
import '@testing-library/jest-dom';

global.SVGPathElement = function () {};

global.MutationObserver = class {
constructor(callback) {}
disconnect() {}
observe(element, initObject) {}
};

global.window.insights = {
...(window.insights || {}),
chrome: {
...((window.insights && window.insights.chrome) || {}),
auth: {
...((window.insights && window.insights.chrome && window.insights.chrome) || {}),
getUser: () =>
new Promise((res) =>
res({
identity: {
// eslint-disable-next-line camelcase
account_number: '0',
type: 'User',
user: {
// eslint-disable-next-line camelcase
is_org_admin: true,
},
},
})
),
},
getUserPermissions: () => new Promise((res) => res([])),
isBeta: () => false,
},
};
jest.mock('react', () => ({
...jest.requireActual('react'),
useLayoutEffect: jest.requireActual('react').useEffect,
}));
Element.prototype.scrollTo = () => {};
4 changes: 2 additions & 2 deletions cypress/component/ErrorBoundary.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ErrorBoundary from '../../packages/module/dist/dynamic/ErrorBoundary';

describe('ErrorBoundary', () => {
it('renders the ErrorBoundary ', () => {
cy.mount(<ErrorBoundary headerTitle="My app header" errorTitle="Something wrong happened"/>)
cy.get('div h1').should('have.text', 'Something wrong happened');
cy.mount(<ErrorBoundary headerTitle="My app header" errorTitle="Something wrong happened"><div data-ouia-component-id="test">Test</div></ErrorBoundary>)
cy.get('[data-ouia-component-id="test"]').should('have.text', 'Test');
});
})
12 changes: 6 additions & 6 deletions fed-mini-modules.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const fse = require('fs-extra');
const glob = require('glob');
const { globSync } = require('glob');
const path = require('path');

const root = process.cwd();

const sourceFiles = glob
.sync(`${root}/src/*/`)
const sourceFiles = globSync(`${root}/src/*/`)
.map((name) => name.replace(/\/$/, ''));

const indexTypings = glob.sync(`${root}/src/index.d.ts`);
const indexTypings = globSync(`${root}/src/index.d.ts`);

async function copyTypings(files, dest) {
const cmds = [];
Expand All @@ -21,7 +20,7 @@ async function copyTypings(files, dest) {

async function createPackage(file) {
const fileName = file.split('/').pop();
const esmSource = glob.sync(`${root}/esm/${fileName}/**/index.js`)[0];
const esmSource = globSync(`${root}/esm/${fileName}/**/index.js`)[0];
/**
* Prevent creating package.json for directories with no JS files (like CSS directories)
*/
Expand All @@ -36,7 +35,7 @@ async function createPackage(file) {
main: 'index.js',
module: esmRelative,
};
const typings = glob.sync(`${root}/src/${fileName}/*.d.ts`);
const typings = globSync(`${root}/src/${fileName}/*.d.ts`);
const cmds = [];
content.typings = 'index.d.ts';
cmds.push(copyTypings(typings, `${root}/${fileName}`));
Expand All @@ -56,6 +55,7 @@ async function run(files) {
copyTypings(indexTypings, root);
}
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
process.exit(1);
}
Expand Down
Loading