Skip to content

Commit

Permalink
fix: Fix the run pipeline in the branch and pipeline list
Browse files Browse the repository at this point in the history
Signed-off-by: harrisonliu5 <harrisonliu_5@163.com>
  • Loading branch information
harrisonliu5 committed Aug 17, 2020
1 parent 2fb0d36 commit 2e7999c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ class BranchSider extends Base {

handleRunBranch = async parameters => {
const { params } = this.props.match
const { branch, devops } = this.props.match.params
const { branch, devops, cluster } = this.props.match.params
const { detail } = this.store

await this.store.runBranch({
devops,
branch,
cluster,
name: detail.name,
parameters,
})
Expand Down
4 changes: 2 additions & 2 deletions src/pages/devops/containers/Pipelines/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ class CICDs extends React.Component {
}

handleRunBranch = async (parameters, branch) => {
const { devops } = this.props.match.params
const { devops, cluster } = this.props.match.params
const { name } = this.state.selectPipeline
await this.store.runBranch({ devops, name, branch, parameters })
await this.store.runBranch({ devops, name, branch, parameters, cluster })
this.props.rootStore.routing.push(
`${this.prefix}/${encodeURIComponent(this.state.selectPipeline.name)}/${
branch ? `branch/${branch}/` : ''
Expand Down
5 changes: 3 additions & 2 deletions src/stores/devops/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with KubeSphere Console. If not, see <https://www.gnu.org/licenses/>.
*/

import { set } from 'lodash'
import { set, get } from 'lodash'
import BaseStore from '../devops'

export default class Base extends BaseStore {
Expand Down Expand Up @@ -51,7 +51,8 @@ export default class Base extends BaseStore {
if (!options) {
options = {}
}
if (globals.user.crumb === undefined) {
const crumb = get(globals, 'user.crumb', '')
if (!crumb) {
const match = url.match(/(clusters|klusters)\/([^/]*)\//)
if (match && match.length === 3) {
const cluster = match[2]
Expand Down
21 changes: 13 additions & 8 deletions src/stores/devops/scm.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,23 @@ export default class SCMStore extends BaseStore {

this.verifyAccessErrorHandle = {
github: (resp, error) => {
const errorBody = error.headers ? resp : error
if (error.code === 428) {
this.isAccessTokenWrong = true
this.orgList.isLoading = false
return
}

if (window.onunhandledrejection) {
window.onunhandledrejection(error)
window.onunhandledrejection(errorBody)
}
return Promise.reject(error)

return Promise.reject(errorBody)
},
'bitbucket-server': (resp, error) => {
if (error.code === 428) {
const errorBody = error.headers ? resp : error

if (errorBody.code === 428) {
this.creatBitBucketServersError = {
password: {
message: t('Wrong username or password, please try again'),
Expand All @@ -50,8 +55,8 @@ export default class SCMStore extends BaseStore {
return
}

if (isArray(error.errors) && !isEmpty(error.errors)) {
this.creatBitBucketServersError = error.errors.reduce(
if (isArray(errorBody.errors) && !isEmpty(errorBody.errors)) {
this.creatBitBucketServersError = errorBody.errors.reduce(
(prev, errorItem) => {
prev[errorItem.field] = { message: errorItem.message }
return prev
Expand All @@ -61,13 +66,13 @@ export default class SCMStore extends BaseStore {
return
}

this.creatBitBucketServersError = { all: error.message }
this.creatBitBucketServersError = { all: errorBody.message }

if (window.onunhandledrejection) {
window.onunhandledrejection(error)
window.onunhandledrejection(errorBody)
}

return Promise.reject(error)
return Promise.reject(errorBody)
},
}

Expand Down
34 changes: 20 additions & 14 deletions src/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,24 +190,12 @@ function handleResponse(response, reject) {
}

return response.text().then(text => {
const error = {
status: response.status,
reason: response.statusText,
message: text,
}

// some errors are the string-json in devops
const errBody = safeParseJSON(text)
if (isObject(errBody) && !isEmpty(errBody)) {
error.status = response.status
error.code = errBody.code
error.message = errBody.message
error.errors = errBody.errors
}
const error = formatTextError(response, text)

if (typeof reject === 'function') {
return reject(response, error)
}

if (window.onunhandledrejection) {
window.onunhandledrejection(error)
}
Expand Down Expand Up @@ -242,3 +230,21 @@ function formatError(response, data) {

return result
}
function formatTextError(response, text) {
let error = {
status: response.status,
reason: response.statusText,
message: text,
}

const errorBody = safeParseJSON(text)
if (isObject(errorBody) && !isEmpty(errorBody)) {
error = {
...error,
code: errorBody.code,
message: errorBody.message,
errors: errorBody.errors,
}
}
return error
}

0 comments on commit 2e7999c

Please sign in to comment.