-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize the Virtual assistant extension (#1)
* Initialize the extension * Update dependencies
- Loading branch information
Showing
44 changed files
with
25,610 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Javascript builds | ||
node_modules | ||
dist | ||
tsc_out | ||
.out | ||
.changelog | ||
.DS_Store | ||
coverage | ||
.cache | ||
.tmp | ||
.eslintcache | ||
generated | ||
__tests__ | ||
|
||
# package managers | ||
lerna-debug.log | ||
|
||
# IDEs and editors | ||
.idea | ||
.project | ||
.classpath | ||
.c9 | ||
*.launch | ||
.settings | ||
*.sublime-workspace | ||
.history | ||
.vscode | ||
.yo-rc.json | ||
|
||
# IDE - VSCode | ||
.vscode | ||
# For vim | ||
*.swp | ||
|
||
public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"plugins": [ | ||
"markdown", | ||
"react" | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": 9, | ||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
}, | ||
"settings": { | ||
"react": { | ||
"version": "16.4.0" | ||
} | ||
}, | ||
"rules": { | ||
"eol-last": 2, | ||
"spaced-comment": 2, | ||
"no-unused-vars": 0, | ||
"no-this-before-super": 2, | ||
"react/jsx-uses-react": "error", | ||
"react/jsx-uses-vars": "error", | ||
"react/no-unknown-property": 2, | ||
"react/jsx-no-undef": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"node": true, | ||
"es6": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:react/recommended", | ||
"plugin:react-hooks/recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier" | ||
], | ||
"overrides": [ | ||
{ | ||
"files": ["**/patternfly-docs/pages/*"], | ||
"rules": { | ||
"arrow-body-style": "off" | ||
} | ||
} | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
}, | ||
"settings": { | ||
"react": { | ||
"version": "detect" | ||
} | ||
}, | ||
"plugins": ["react", "react-hooks", "@typescript-eslint"], | ||
"rules": { | ||
"@typescript-eslint/adjacent-overload-signatures": "error", | ||
"@typescript-eslint/array-type": "error", | ||
"@typescript-eslint/consistent-type-assertions": "error", | ||
"@typescript-eslint/consistent-type-definitions": "error", | ||
"@typescript-eslint/no-misused-new": "error", | ||
"@typescript-eslint/no-namespace": "error", | ||
"@typescript-eslint/no-unused-vars": [ | ||
"error", | ||
{ | ||
"argsIgnorePattern": "^_" | ||
} | ||
], | ||
"@typescript-eslint/prefer-for-of": "error", | ||
"@typescript-eslint/prefer-function-type": "error", | ||
"@typescript-eslint/prefer-namespace-keyword": "error", | ||
"@typescript-eslint/unified-signatures": "error", | ||
"@typescript-eslint/no-var-requires": "off", | ||
"arrow-body-style": "error", | ||
"array-bracket-spacing": ["error", "always"], | ||
"camelcase": [ | ||
"error", | ||
{ | ||
"ignoreDestructuring": true | ||
} | ||
], | ||
"constructor-super": "error", | ||
"curly": "error", | ||
"dot-notation": "error", | ||
"eqeqeq": ["error", "smart"], | ||
"guard-for-in": "error", | ||
"indent": ["error", 2], | ||
"max-classes-per-file": ["error", 1], | ||
"no-nested-ternary": "error", | ||
"no-bitwise": "error", | ||
"no-caller": "error", | ||
"no-cond-assign": "error", | ||
"no-console": "error", | ||
"no-debugger": "error", | ||
"no-empty": "error", | ||
"no-eval": "error", | ||
"no-new-wrappers": "error", | ||
"no-undef-init": "error", | ||
"no-unsafe-finally": "error", | ||
"no-unused-expressions": [ | ||
"error", | ||
{ | ||
"allowTernary": true, | ||
"allowShortCircuit": true | ||
} | ||
], | ||
"no-unused-labels": "error", | ||
"no-var": "error", | ||
"object-shorthand": "error", | ||
"object-curly-spacing": ["error", "always"], | ||
"one-var": ["error", "never"], | ||
"prefer-const": "error", | ||
"radix": ["error", "as-needed"], | ||
"react/prop-types": 0, | ||
"react/display-name": 0, | ||
"react-hooks/exhaustive-deps": "warn", | ||
"react/no-unescaped-entities": ["error", { "forbid": [">", "}"] }], | ||
"spaced-comment": "error", | ||
"use-isnan": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
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 || ''; | ||
|
||
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 uploadFolder = process.argv[2]; | ||
if (!uploadFolder) { | ||
console.log('Usage: upload-preview uploadFolder'); | ||
process.exit(1); | ||
} | ||
|
||
const uploadFolderName = path.basename(uploadFolder); | ||
let uploadURL = `${repo}-${prnum ? `pr-virtual-assistant-${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; | ||
} | ||
|
||
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; | ||
} | ||
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 (uploadFolderName === 'public') { | ||
commentBody += tryAddComment(`Preview: https://${uploadURL}`, commentBody); | ||
} | ||
else if (uploadFolderName === 'coverage') { | ||
commentBody += tryAddComment(`A11y report: https://${uploadURL}`, commentBody); | ||
} | ||
|
||
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!')); | ||
} | ||
}); | ||
} |
Oops, something went wrong.