-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add build status to project upload #542
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4558a15
add status endpoint
anthmatic d9aa6f9
first pass at showing build statuses
anthmatic 2095d41
fix dep name
anthmatic 023d0b4
renamed projects folder and files to project to match command name ch…
miketalley d12819d
fixed issue with undefined spinner after project build completion and…
miketalley 54251c7
yarn.lock changes
miketalley 95172cf
cleanup including adding pending status
miketalley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -4,10 +4,24 @@ const path = require('path'); | |
const chalk = require('chalk'); | ||
const findup = require('findup-sync'); | ||
const { prompt } = require('inquirer'); | ||
const Spinnies = require('spinnies'); | ||
const { logger } = require('@hubspot/cli-lib/logger'); | ||
const { getEnv } = require('@hubspot/cli-lib/lib/config'); | ||
const { getHubSpotWebsiteOrigin } = require('@hubspot/cli-lib/lib/urls'); | ||
const { ENVIRONMENTS } = require('@hubspot/cli-lib/lib/constants'); | ||
const { | ||
ENVIRONMENTS, | ||
POLLING_DELAY, | ||
PROJECT_BUILD_STATUS, | ||
PROJECT_BUILD_STATUS_TEXT, | ||
} = require('@hubspot/cli-lib/lib/constants'); | ||
const { getBuildStatus } = require('@hubspot/cli-lib/api/dfs'); | ||
|
||
const isBuildComplete = build => { | ||
return ( | ||
build.status === PROJECT_BUILD_STATUS.SUCCESS || | ||
build.status === PROJECT_BUILD_STATUS.FAILURE | ||
); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😀 |
||
|
||
const writeProjectConfig = (configPath, config) => { | ||
try { | ||
|
@@ -113,10 +127,82 @@ const showWelcomeMessage = (projectName, accountId) => { | |
); | ||
}; | ||
|
||
const pollBuildStatus = async (accountId, name, buildId) => { | ||
const buildStatus = await getBuildStatus(accountId, name, buildId); | ||
const spinnies = new Spinnies(); | ||
|
||
logger.log(`Building project '${name}'...`); | ||
for (let subBuild of buildStatus.subbuildStatuses) { | ||
spinnies.add(subBuild.buildName, { | ||
text: `'${subBuild.buildName}' ${ | ||
PROJECT_BUILD_STATUS_TEXT[PROJECT_BUILD_STATUS.ENQUEUED] | ||
}`, | ||
}); | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
const pollInterval = setInterval(async () => { | ||
const buildStatus = await getBuildStatus(accountId, name, buildId).catch( | ||
reject | ||
); | ||
const { status, subbuildStatuses } = buildStatus; | ||
|
||
if (Object.keys(spinnies.spinners).length) { | ||
subbuildStatuses.forEach(subBuild => { | ||
const updatedText = `'${subBuild.buildName}' ${ | ||
PROJECT_BUILD_STATUS_TEXT[subBuild.status] | ||
}`; | ||
|
||
switch (subBuild.status) { | ||
case PROJECT_BUILD_STATUS.SUCCESS: | ||
spinnies.succeed(subBuild.buildName, { | ||
text: updatedText, | ||
}); | ||
break; | ||
case PROJECT_BUILD_STATUS.FAILURE: | ||
spinnies.fail(subBuild.buildName, { | ||
text: updatedText, | ||
}); | ||
break; | ||
default: | ||
spinnies.update(subBuild.buildName, { | ||
text: updatedText, | ||
}); | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
if (isBuildComplete(buildStatus)) { | ||
clearInterval(pollInterval); | ||
|
||
if (status === PROJECT_BUILD_STATUS.SUCCESS) { | ||
logger.success( | ||
`Your project '${name}' ${PROJECT_BUILD_STATUS_TEXT[status]}.` | ||
); | ||
} else if (status === PROJECT_BUILD_STATUS.FAILURE) { | ||
logger.error( | ||
`Your project '${name}' ${PROJECT_BUILD_STATUS_TEXT[status]}.` | ||
); | ||
subbuildStatuses.forEach(subBuild => { | ||
if (subBuild.status === PROJECT_BUILD_STATUS.FAILURE) { | ||
logger.error( | ||
`${subBuild.buildName} failed to build. ${subBuild.errorMessage}.` | ||
); | ||
} | ||
}); | ||
} | ||
resolve(buildStatus); | ||
} | ||
}, POLLING_DELAY); | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
writeProjectConfig, | ||
getProjectConfig, | ||
getOrCreateProjectConfig, | ||
validateProjectConfig, | ||
showWelcomeMessage, | ||
pollBuildStatus, | ||
}; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We were usingora
for loading spinners elsewhere in the CLI. Is there a reason to have both or should we useora
here also?It looks like having multiple spinners displayed simultaneously for the purpose of displaying the status of the subbuilds is not possible using
ora
. I think we should work on updating uses ofora
to usespinnies
in the future.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.
Yeah, that's exactly it and I agree