Skip to content
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

fix: Update calls in project creation to download the entire repo #1326

Merged
merged 13 commits into from
Jan 22, 2025

Conversation

joe-yeager
Copy link
Contributor

@joe-yeager joe-yeager commented Jan 9, 2025

Description and Context

Depends on HubSpot/hubspot-local-dev-lib#224

The calls in project creation were fetching the individual files one by one instead of fetching the entire repo in one pass. This was increasing the rate at which we would hit the github rate limit, which is 60 rpm for unauthorized requests.

Testing

Here is a script I have been using to compare the diff of the directories generated by hs create and hs project create in the prod (hs) and local (yarn hs) versions to verify the behavior remains the same. The last 3 create types require manual input that is unable to be overridden with command flags, so you will need to manually input data twice (once for prod and once for local). Make sure the fields you choose match or the diff will fail because the assets/names are different.

You will need a token or this script will hit the rate limit.
To generate a token:

GH_TOKEN="generate a token that has public repo read"

function diffdir() {
  if [ ! -d "$1" ]; then
    printf "\e[1;31m%s does not exist.\e[1;0m" "$1"
    return
  fi

  if [ ! -d "$2" ]; then
    printf "\e[1;31m%s does not exist.\e[1;0m" "$2"
    return
  fi

  result=$(diff -r $1 $2)
  if [ -z "$result" ]; then
    printf "\e[1;32m%s and %s are the same\e[1;0m\n" "$1" "$2"
  else
    printf "\e[1;31m%s and %s are different\e[1;0m\n\n Please manually verify \n\n" "$1" "$2"
  fi
}

function testCreateProject() {
    GITHUB_TOKEN=$GH_TOKEN hs project create --name "$1" --dest "$2-prod" --template "$3" > /dev/null
    GITHUB_TOKEN=$GH_TOKEN NODE_NO_WARNINGS=1 yarn hs project create --name "$1" --dest "$2-local" --template "$3" > /dev/null

    diffdir "$2-prod" "$2-local"
}

function testCreate() {
    GITHUB_TOKEN=$GH_TOKEN hs create "$1" "$2-prod" "$3-prod"
    GITHUB_TOKEN=$GH_TOKEN NODE_NO_WARNINGS=1 yarn hs create "$1" "$2-local" "$3-prod"

    diffdir "$2-prod" "$2-local"
}

function testCreateModuleTemplate() {
    GITHUB_TOKEN=$GH_TOKEN hs create "$1" "$2-prod" "$3"
    GITHUB_TOKEN=$GH_TOKEN NODE_NO_WARNINGS=1 yarn hs create "$1" "$2-local" "$3"

}

rm -rf scripted-* module* template*

echo "Testing hs project create getting-started-private-app"
testCreateProject private-app scripted-private-app getting-started-private-app

echo "Testing hs project create getting-started-public-app"
testCreateProject public-app scripted-public-app getting-started-public-app

echo "Testing hs project create no-template"
testCreateProject no-template scripted-no-template no-template

echo "Testing create vue-app"
testCreate vue-app scripted-vue-app vue-app

echo "Testing create webpack-serverless"
testCreate webpack-serverless scripted-webpack-serverless webpack-serverless

echo "Testing create website-theme"
testCreate website-theme scripted-website-theme website-theme

echo "Testing create react-app"
testCreate react-app scripted-react-app react-app

echo "Testing create function"
testCreate function scripted-function function

echo "Testing create module"
testCreateModuleTemplate module scripted-module module
echo "These need to be manually verified using diff\n"

echo "Testing create template"
testCreateModuleTemplate template scripted-template template
result=$(diff template/scripted-template-prod.html template/scripted-template-local.html)
if [ -z "$result" ]; then
  printf "\e[1;32mTemplates match\e[1;0m\n"
else
  printf "\e[1;31mTemplate do not match\e[1;0m\n\n Please manually verify \n\n"
fi

package.json Outdated Show resolved Hide resolved
@joe-yeager joe-yeager changed the base branch from main to jy/fix-generic-error-message-for-invalid-template-source January 21, 2025 21:47
…e' of github.com:HubSpot/hubspot-cli into jy/fix-gh-rate-limit
Base automatically changed from jy/fix-generic-error-message-for-invalid-template-source to main January 21, 2025 22:44
brandenrodgers
brandenrodgers previously approved these changes Jan 22, 2025
Copy link
Contributor

@brandenrodgers brandenrodgers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested and everything lgtm!

Comment on lines +92 to +97
yargs.example([
[
'$0 project create --template-source HubSpot/ui-extensions-examples',
i18n(`${i18nKey}.examples.templateSource`),
],
]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was super confusing to use. Added an example

lang/en.lyaml Outdated Show resolved Hide resolved
brandenrodgers
brandenrodgers previously approved these changes Jan 22, 2025
Copy link
Contributor

@brandenrodgers brandenrodgers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one question on punctuation, but otherwise the new example looks good to me

@joe-yeager joe-yeager merged commit 91cf915 into main Jan 22, 2025
1 check passed
@joe-yeager joe-yeager deleted the jy/fix-gh-rate-limit branch January 22, 2025 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants