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: glitch hides github login behind a login button that is now clicked first by puppeteer #11

Merged
merged 2 commits into from
Sep 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions bin/glitch-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const debug = require('debug')('glitch-deploy')

if (process.env.CI) {
debug('Running on CI, checking for environment varibales')
debug('Running on CI, checking for environment variables')
require('../lib/env.js')
}

Expand All @@ -18,15 +18,16 @@ const getGlitchNameAndRepo = require('../lib/get-glitch-name-and-repo')
const getPackageDefaults = require('../lib/get-package-defaults')
const handleGithub2faAuthentication = require('../lib/handle-github-2fa-authentication')
const importGitHubRepo = require('../lib/import-github-repo')

;(async () => {
const state = {
debug: debug,
defaults: getPackageDefaults(),
browser: await puppeteer.launch({
// https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions
headless: !process.env.SHOW_BROWSER,
args: process.env.CI ? ['--no-sandbox', '--disable-setuid-sandbox'] : undefined
args: process.env.CI
? ['--no-sandbox', '--disable-setuid-sandbox']
: undefined
})
}

Expand All @@ -44,7 +45,11 @@ const importGitHubRepo = require('../lib/import-github-repo')
// page.click does not work with given selector
// await state.page.click('[href^="https://github.com/login/oauth/authorize"]')
await state.page.evaluate(() => {
document.querySelector('[href^="https://github.com/login/oauth/authorize"]').click()
const buttons = [...document.querySelectorAll('button')]
buttons.find((button) => button.textContent === 'Sign in').click()
document
.querySelector('[href^="https://github.com/login/oauth/authorize"]')
.click()
})

debug('Login with GitHub')
Expand Down Expand Up @@ -73,7 +78,9 @@ const importGitHubRepo = require('../lib/import-github-repo')
return state.browser.close()
}

const glitchAuthToken = await state.page.evaluate(() => JSON.parse(window.localStorage.getItem('cachedUser')).persistentToken)
const glitchAuthToken = await state.page.evaluate(
() => JSON.parse(window.localStorage.getItem('cachedUser')).persistentToken
)
debug(`glitchAuthToken: ${glitchAuthToken.substr(0, 5)}***`)

if (glitchApp === null && glitchInfo.doCreate) {
Expand Down Expand Up @@ -108,6 +115,8 @@ const importGitHubRepo = require('../lib/import-github-repo')
debug(`Opening https://${glitchApp.domain}.glitch.me ...`)
await state.page.goto(`https://${glitchApp.domain}.glitch.me`)

console.log(`${glitchInfo.repoName} deployed to https://${glitchApp.domain}.glitch.me`)
console.log(
`${glitchInfo.repoName} deployed to https://${glitchApp.domain}.glitch.me`
)
state.browser.close()
})()