-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into readme-updates
- Loading branch information
Showing
11 changed files
with
135 additions
and
50 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
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
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
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
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 |
---|---|---|
|
@@ -20,10 +20,10 @@ describe('CML e2e', () => { | |
--help Show help [boolean] | ||
Options: | ||
--unshallow Fetch as much as possible, converting a shallow repository to a | ||
complete one [boolean] | ||
--user-email Git user email [string] [default: \\"[email protected]\\"] | ||
--user-name Git user name [string] [default: \\"Olivaw[bot]\\"]" | ||
--fetch-depth Number of commits to fetch (use \`0\` for all branches & tags) | ||
[number] | ||
--user-email Git user email [string] [default: \\"[email protected]\\"] | ||
--user-name Git user name [string] [default: \\"Olivaw[bot]\\"]" | ||
`); | ||
}); | ||
}); |
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
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ const { | |
|
||
const { GITHUB_REPOSITORY, CI_PROJECT_URL, BITBUCKET_REPO_UUID } = process.env; | ||
|
||
const WATERMARK_IMAGE = 'https://cml.dev/watermark.png'; | ||
const GIT_USER_NAME = 'Olivaw[bot]'; | ||
const GIT_USER_EMAIL = '[email protected]'; | ||
const GIT_REMOTE = 'origin'; | ||
|
@@ -164,26 +165,55 @@ class CML { | |
const triggerSha = await this.triggerSha(); | ||
const { | ||
commitSha: inCommitSha = triggerSha, | ||
rmWatermark, | ||
update, | ||
markdownFile, | ||
pr, | ||
publish, | ||
publishUrl, | ||
markdownFile, | ||
report: testReport, | ||
rmWatermark, | ||
triggerFile, | ||
update, | ||
watch, | ||
triggerFile | ||
watermarkTitle | ||
} = opts; | ||
|
||
const drv = this.getDriver(); | ||
|
||
const commitSha = | ||
(await this.revParse({ ref: inCommitSha })) || inCommitSha; | ||
|
||
if (rmWatermark && update) | ||
throw new Error('watermarks are mandatory for updateable comments'); | ||
|
||
// Create the watermark. | ||
const genWatermark = (opts = {}) => { | ||
const { label = '', workflow, run } = opts; | ||
// Replace {workflow} and {run} placeholders in label with actual values. | ||
const lbl = label.replace('{workflow}', workflow).replace('{run}', run); | ||
|
||
let title = `CML watermark ${lbl}`.trim(); | ||
// Github appears to escape underscores and asterisks in markdown content. | ||
// Without escaping them, the watermark content in comments retrieved | ||
// from github will not match the input. | ||
const patterns = [ | ||
[/_/g, '\\_'], // underscore | ||
[/\*/g, '\\*'], // asterisk | ||
[/\[/g, '\\['], // opening square bracket | ||
[/</g, '\\<'] // opening angle bracket | ||
]; | ||
title = patterns.reduce( | ||
(label, pattern) => label.replace(pattern[0], pattern[1]), | ||
title | ||
); | ||
return `![](${WATERMARK_IMAGE} "${title}")`; | ||
}; | ||
const watermark = rmWatermark | ||
? '' | ||
: '![CML watermark](https://raw.githubusercontent.com/iterative/cml/master/assets/watermark.svg)'; | ||
: genWatermark({ | ||
label: watermarkTitle, | ||
workflow: drv.workflowId, | ||
run: drv.runId | ||
}); | ||
|
||
let userReport = testReport; | ||
try { | ||
|
@@ -195,15 +225,17 @@ class CML { | |
} | ||
|
||
let report = `${userReport}\n\n${watermark}`; | ||
const drv = this.getDriver(); | ||
|
||
const publishLocalFiles = async (tree) => { | ||
const nodes = []; | ||
|
||
visit(tree, ['definition', 'image', 'link'], (node) => nodes.push(node)); | ||
|
||
const isWatermark = (node) => { | ||
return node.title && node.title.startsWith('CML watermark'); | ||
}; | ||
const visitor = async (node) => { | ||
if (node.url && node.alt !== 'CML watermark') { | ||
if (node.url && !isWatermark(node)) { | ||
const absolutePath = path.resolve( | ||
path.dirname(markdownFile), | ||
node.url | ||
|
@@ -264,7 +296,7 @@ class CML { | |
let comment; | ||
const updatableComment = (comments) => { | ||
return comments.reverse().find(({ body }) => { | ||
return body.includes('watermark.svg'); | ||
return body.includes(watermark); | ||
}); | ||
}; | ||
|
||
|
@@ -469,15 +501,19 @@ class CML { | |
userName = GIT_USER_NAME, | ||
remote = GIT_REMOTE | ||
} = opts; | ||
const { fetchDepth = unshallow ? 0 : undefined } = opts; | ||
|
||
const driver = this.getDriver(); | ||
await exec(await driver.updateGitConfig({ userName, userEmail, remote })); | ||
if (unshallow) { | ||
if ((await exec('git rev-parse --is-shallow-repository')) === 'true') { | ||
await exec('git fetch --unshallow'); | ||
if (fetchDepth !== undefined) { | ||
if (fetchDepth <= 0) { | ||
if ((await exec('git rev-parse --is-shallow-repository')) === 'true') { | ||
return await exec('git fetch --all --unshallow'); | ||
} | ||
} else { | ||
return await exec(`git fetch --all --depth=${fetchDepth}`); | ||
} | ||
} | ||
await exec('git fetch --all'); | ||
} | ||
|
||
async prCreate(opts = {}) { | ||
|
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
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
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
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
f641e58
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test Comment
f641e58
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test Comment