-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
feat(releases): creating releases in git backend #6854
base: main
Are you sure you want to change the base?
Changes from 1 commit
357634a
47e2be0
dc01c88
d2e1603
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -818,6 +818,36 @@ export default class API { | |
return cmsBranches; | ||
} | ||
|
||
async latestRelease() { | ||
console.log( | ||
'%c Loading latest release', | ||
'line-height: 30px;text-align: center;font-weight: bold', | ||
); | ||
|
||
return this.request(`${this.repoURL}/releases/latest`) | ||
} | ||
|
||
async listReleases() { | ||
console.log( | ||
'%c Loading releases', | ||
'line-height: 30px;text-align: center;font-weight: bold', | ||
); | ||
|
||
return this.request(`${this.repoURL}/releases`) | ||
} | ||
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. you may want to do error handeling here ? |
||
|
||
async publishRelease(version: string) { | ||
console.log( | ||
`%c Publishing release ${version}`, | ||
'line-height: 30px;text-align: center;font-weight: bold', | ||
); | ||
|
||
return this.request(`${this.repoURL}/releases`, { | ||
method: 'POST', | ||
body: JSON.stringify({ tag_name: version }), | ||
}); | ||
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. ditto |
||
} | ||
|
||
async listUnpublishedBranches() { | ||
console.log( | ||
'%c Checking for Unpublished entries', | ||
|
@@ -1449,6 +1479,7 @@ export default class API { | |
author?: GitHubAuthor, | ||
committer?: GitHubCommitter, | ||
) { | ||
console.log(message); | ||
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. this looks like it should either be removed or switched to the logging format. |
||
const result: Octokit.GitCreateCommitResponse = await this.request( | ||
`${this.repoURL}/git/commits`, | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -579,6 +579,22 @@ export default class GitHub implements Implementation { | |
}; | ||
} | ||
|
||
async listReleases() { | ||
try { | ||
return await this.api!.listReleases(); | ||
} catch (e) { | ||
return []; | ||
} | ||
} | ||
|
||
async publishRelease(version: string) { | ||
try { | ||
return await this.api!.publishRelease(version); | ||
} catch (e) { | ||
return; | ||
} | ||
} | ||
|
||
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. the rest of the code prefers the .then() syntax, you should probably respect that and write it as: return await this.api!.listReleases().catch(e => ([])) |
||
async unpublishedEntries() { | ||
const listEntriesKeys = () => | ||
this.api!.listUnpublishedBranches().then(branches => | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,10 +43,10 @@ | |
"jwt-decode": "^3.0.0", | ||
"node-polyglot": "^2.3.0", | ||
"prop-types": "^15.7.2", | ||
"react": "^16.8.4", | ||
"react": "^16.8.4 || ^17.0.0", | ||
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. you should probably justify this react deps bump |
||
"react-dnd": "^14.0.0", | ||
"react-dnd-html5-backend": "^14.0.0", | ||
"react-dom": "^16.8.4", | ||
"react-dom": "^16.8.4 || ^17.0.0", | ||
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. ditto |
||
"react-frame-component": "^5.2.1", | ||
"react-hot-loader": "^4.8.0", | ||
"react-immutable-proptypes": "^2.1.0", | ||
|
@@ -71,6 +71,7 @@ | |
"remark-gfm": "1.0.0", | ||
"sanitize-filename": "^1.6.1", | ||
"semaphore": "^1.0.5", | ||
"semver": "^7.5.4", | ||
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. please document why you want semver 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. to conveniently bump the version. will document |
||
"tomlify-j0.4": "^3.0.0-alpha.0", | ||
"url": "^0.11.0", | ||
"url-join": "^4.0.1", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { actions as notifActions } from 'redux-notifications'; | ||
import { currentBackend } from '../backend'; | ||
import type { | ||
State, | ||
Releases, | ||
} from '../types/redux'; | ||
import type { AnyAction } from 'redux'; | ||
import type { ThunkDispatch } from 'redux-thunk'; | ||
|
||
const { notifSend } = notifActions; | ||
|
||
/* | ||
* Constant Declarations | ||
*/ | ||
export const RELEASES_REQUEST = 'RELEASES_REQUEST'; | ||
export const RELEASES_SUCCESS = 'RELEASES_SUCCESS'; | ||
export const RELEASES_FAILURE = 'RELEASES_FAILURE'; | ||
export const RELEASE_PUBLICATION_REQUEST = 'RELEASE_PUBLICATION_REQUEST'; | ||
export const RELEASE_PUBLICATION_SUCCESS = 'RELEASE_PUBLICATION_SUCCESS'; | ||
export const RELEASE_PUBLICATION_FAILURE = 'RELEASE_PUBLICATION_FAILURE'; | ||
|
||
/* | ||
* Simple Action Creators (Internal) | ||
*/ | ||
|
||
function releasesLoading() { | ||
return { | ||
type: RELEASES_REQUEST, | ||
}; | ||
} | ||
|
||
function releasesLoaded(releases: Releases) { | ||
return { | ||
type: RELEASES_SUCCESS, | ||
payload: releases, | ||
}; | ||
} | ||
|
||
function releasesFailed(error: Error) { | ||
return { | ||
type: RELEASES_FAILURE, | ||
error: 'Failed to load releases', | ||
payload: error, | ||
}; | ||
} | ||
|
||
function releasePublicationLoading() { | ||
return { | ||
type: RELEASE_PUBLICATION_REQUEST, | ||
}; | ||
} | ||
|
||
function releasePublicationSuccess() { | ||
console.log(RELEASE_PUBLICATION_SUCCESS); | ||
return { | ||
type: RELEASE_PUBLICATION_SUCCESS, | ||
}; | ||
} | ||
|
||
function releasePublicationFailed(error: Error) { | ||
return { | ||
type: RELEASE_PUBLICATION_FAILURE, | ||
error: 'Failed to publish release', | ||
payload: error, | ||
}; | ||
} | ||
|
||
/* | ||
* Exported Thunk Action Creators | ||
*/ | ||
|
||
export function loadReleases() { | ||
return (dispatch: ThunkDispatch<State, {}, AnyAction>, getState: () => State) => { | ||
const state = getState(); | ||
const backend = currentBackend(state.config); | ||
|
||
dispatch(releasesLoading()); | ||
backend | ||
.listReleases() | ||
.then(response => dispatch(releasesLoaded(response))) | ||
.catch((error: Error) => { | ||
dispatch( | ||
notifSend({ | ||
message: { | ||
key: 'ui.toast.onFailToLoadEntries', | ||
details: error, | ||
}, | ||
kind: 'danger', | ||
dismissAfter: 8000, | ||
}), | ||
); | ||
dispatch(releasesFailed(error)); | ||
Promise.reject(error); | ||
}); | ||
}; | ||
} | ||
|
||
export function createRelease(version: 'string') { | ||
return async (dispatch: ThunkDispatch<State, {}, AnyAction>, getState: () => State) => { | ||
const state = getState(); | ||
const backend = currentBackend(state.config); | ||
|
||
dispatch(releasePublicationLoading()); | ||
|
||
try { | ||
await backend.publishRelease(version) | ||
dispatch( | ||
notifSend({ | ||
message: { | ||
key: 'ui.toast.releasePublished', | ||
}, | ||
kind: 'success', | ||
dismissAfter: 4000, | ||
}), | ||
); | ||
dispatch(releasePublicationSuccess()); | ||
} catch (error: any) { | ||
dispatch( | ||
notifSend({ | ||
message: { | ||
key: 'ui.toast.onReleaseFailed', | ||
details: error, | ||
}, | ||
kind: 'danger', | ||
dismissAfter: 8000, | ||
}), | ||
); | ||
return Promise.reject( | ||
dispatch(releasePublicationFailed(error)), | ||
); | ||
} finally { | ||
setTimeout(() => { | ||
dispatch(loadReleases()) | ||
}, 2000); | ||
} | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import Workflow from '../Workflow/Workflow'; | |
import Editor from '../Editor/Editor'; | ||
import NotFoundPage from './NotFoundPage'; | ||
import Header from './Header'; | ||
import Releases from '../Releases/Releases'; | ||
|
||
TopBarProgress.config({ | ||
barColors: { | ||
|
@@ -172,6 +173,7 @@ class App extends React.Component { | |
|
||
const defaultPath = getDefaultPath(collections); | ||
const hasWorkflow = publishMode === EDITORIAL_WORKFLOW; | ||
const isGitBackend = currentBackend(this.props.config).isGitBackend(); | ||
|
||
return ( | ||
<> | ||
|
@@ -186,6 +188,7 @@ class App extends React.Component { | |
displayUrl={config.display_url} | ||
isTestRepo={config.backend.name === 'test-repo'} | ||
showMediaButton={showMediaButton} | ||
isGitBackend={isGitBackend} | ||
/> | ||
<AppMainContainer> | ||
{isFetching && <TopBarProgress />} | ||
|
@@ -205,6 +208,7 @@ class App extends React.Component { | |
to={defaultPath} | ||
/> | ||
{hasWorkflow ? <Route path="/workflow" component={Workflow} /> : null} | ||
{isGitBackend ? <Route path="/releases" component={Releases}/> : null } | ||
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. this seems to only work for github, is checking isGitBackend() enough to ensure we're in GitHub land ? 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. I was planning to add implementations for the other providers. |
||
<RouteInCollection | ||
exact | ||
collections={collections} | ||
|
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.
this should probably not link to your repo