100: Batched repository selection #119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ import 'isomorphic-fetch'; | |
|
||
import { checkStatus, getError } from '../helpers/api'; | ||
import { conf } from '../helpers/config'; | ||
import { parseGitHubRepoUrl } from '../helpers/github-url'; | ||
|
||
const BASE_URL = conf.get('BASE_URL'); | ||
|
||
|
@@ -54,10 +53,11 @@ function getSnapName(owner, name) { | |
})); | ||
} | ||
|
||
export function createSnap(repositoryUrl, location) { // location for tests | ||
export function createSnap(repository) { | ||
return (dispatch) => { | ||
const repositoryUrl = repository.url; | ||
if (repositoryUrl) { | ||
const { owner, name, fullName } = parseGitHubRepoUrl(repositoryUrl); | ||
const { owner, name, fullName } = repository; | ||
|
||
dispatch({ | ||
type: CREATE_SNAP, | ||
|
@@ -81,30 +81,45 @@ export function createSnap(repositoryUrl, location) { // location for tests | |
.then(checkStatus) | ||
.then(response => { | ||
return response.json().then(result => { | ||
if (result.status !== 'success' || | ||
result.payload.code !== 'snap-created') { | ||
throw getError(response, result); | ||
if (result.status !== 'success' || result.payload.code !== 'snap-created') { | ||
return Promise.reject(getError(response, result)); | ||
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 startingUrl = `${BASE_URL}/${fullName}/setup`; | ||
(location || window.location).href = | ||
`${BASE_URL}/login/authenticate` + | ||
`?starting_url=${encodeURIComponent(startingUrl)}` + | ||
`&caveat_id=${encodeURIComponent(result.payload.message)}` + | ||
`&repository_url=${encodeURIComponent(repositoryUrl)}`; | ||
|
||
return Promise.resolve(result); | ||
}); | ||
}) | ||
.catch(error => { | ||
// if LP error says there is already such snap, just redirect to builds page | ||
if (error.message === 'There is already a snap package with the same name and owner.') { | ||
(location || window.location).href = `${BASE_URL}/${fullName}/builds`; | ||
} else { | ||
dispatch(createSnapError(fullName, error)); | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
|
||
export function createSnaps(repositories, location) { // location for tests | ||
return (dispatch) => { | ||
// Patch the creation of multiple snaps | ||
// until auth supports it. Until then, | ||
// only process the first selected repo | ||
repositories = [ repositories[0] ]; | ||
const { fullName, url } = repositories[0]; | ||
|
||
const promises = repositories.map((repository) => dispatch(createSnap(repository))); | ||
return Promise.all(promises) | ||
.then((results) => { | ||
// Redirect to Launchpad auth for the first | ||
// selected repo until auth supports batched | ||
// creation of snaps | ||
const startingUrl = `${BASE_URL}/${fullName}/setup`; | ||
|
||
(location || window.location).href = | ||
`${BASE_URL}/login/authenticate` + | ||
`?starting_url=${encodeURIComponent(startingUrl)}` + | ||
`&caveat_id=${encodeURIComponent(results[0].payload.message)}` + | ||
`&repository_url=${encodeURIComponent(url)}`; | ||
}) | ||
.catch(error => { | ||
dispatch(createSnapError(fullName, error)); | ||
}); | ||
}; | ||
} | ||
|
||
export function createSnapError(id, error) { | ||
return { | ||
type: CREATE_SNAP_ERROR, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ export const verify = (req, res, next) => { | |
logger.info('User successfully authenticated'); | ||
|
||
// Redirect to logged in URL | ||
res.redirect('/dashboard'); | ||
res.redirect('/dashboard/select-repositories'); | ||
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. After logging in, redirect to the dashboard select-repositories view as if logging in for the first time. 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. We don't technically need this change. Eventually, the user will only be redirected to the select-repositories view if they have no enabled repositories. The reason I made this change now is that it will allow us to validate the "initial login" path before the smarter redirect is in-place. Our designers can see a more complete picture of the site before the "enabled-repositories" dashboard view is finished. It's a small, meaningless change but I think it speaks a lot. 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. OK. We probably need full workflow (with usable dashboard and enabled repos list and 'smarter' redirect) before it's meaningful to discuss the complete picture, but it doesn't hurt to have this for now. |
||
}); | ||
}; | ||
|
||
|
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.
Unrelated codestyle change.