Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
20dfb127
Commit
20dfb127
authored
Feb 15, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved some methods around to make it less complex
parent
3b091a9f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
29 deletions
+39
-29
app/assets/javascripts/ide/components/repo_commit_section.vue
...assets/javascripts/ide/components/repo_commit_section.vue
+1
-1
app/assets/javascripts/ide/stores/modules/commit/actions.js
app/assets/javascripts/ide/stores/modules/commit/actions.js
+23
-28
app/assets/javascripts/ide/stores/utils.js
app/assets/javascripts/ide/stores/utils.js
+15
-0
No files found.
app/assets/javascripts/ide/components/repo_commit_section.vue
View file @
20dfb127
...
@@ -133,7 +133,7 @@ export default {
...
@@ -133,7 +133,7 @@ export default {
:disabled=
"discardDraftButtonDisabled"
:disabled=
"discardDraftButtonDisabled"
@
click=
"discardDraft"
@
click=
"discardDraft"
>
>
Discard draft
{{
__
(
'
Discard draft
'
)
}}
</button>
</button>
</div>
</div>
</form>
</form>
...
...
app/assets/javascripts/ide/stores/modules/commit/actions.js
View file @
20dfb127
import
*
as
types
from
'
./mutation_types
'
;
import
*
as
types
from
'
./mutation_types
'
;
import
*
as
consts
from
'
./constants
'
;
import
*
as
consts
from
'
./constants
'
;
import
*
as
rootTypes
from
'
../../mutation_types
'
;
import
*
as
rootTypes
from
'
../../mutation_types
'
;
import
{
createCommitPayload
,
createNewMergeRequestUrl
}
from
'
../../utils
'
;
import
router
from
'
../../../ide_router
'
;
import
router
from
'
../../../ide_router
'
;
import
service
from
'
../../../services
'
;
import
service
from
'
../../../services
'
;
import
flash
from
'
../../../../flash
'
;
import
flash
from
'
../../../../flash
'
;
...
@@ -23,6 +24,16 @@ export const updateBranchName = ({ commit }, branchName) => {
...
@@ -23,6 +24,16 @@ export const updateBranchName = ({ commit }, branchName) => {
commit
(
types
.
UPDATE_NEW_BRANCH_NAME
,
branchName
);
commit
(
types
.
UPDATE_NEW_BRANCH_NAME
,
branchName
);
};
};
export
const
setLastCommitMessage
=
({
commit
},
data
)
=>
{
let
commitMsg
=
`Your changes have been committed. Commit
${
data
.
short_id
}
`
;
if
(
data
.
stats
)
{
commitMsg
+=
` with
${
data
.
stats
.
additions
}
additions,
${
data
.
stats
.
deletions
}
deletions.`
;
}
commit
(
rootTypes
.
SET_LAST_COMMIT_MSG
,
commitMsg
,
{
root
:
true
});
};
export
const
checkCommitStatus
=
({
rootState
})
=>
export
const
checkCommitStatus
=
({
rootState
})
=>
service
service
.
getBranchData
(
rootState
.
currentProjectId
,
rootState
.
currentBranchId
)
.
getBranchData
(
rootState
.
currentProjectId
,
rootState
.
currentBranchId
)
...
@@ -41,7 +52,7 @@ export const checkCommitStatus = ({ rootState }) =>
...
@@ -41,7 +52,7 @@ export const checkCommitStatus = ({ rootState }) =>
export
const
updateFilesAfterCommit
=
(
export
const
updateFilesAfterCommit
=
(
{
commit
,
dispatch
,
state
,
rootState
,
rootGetters
},
{
commit
,
dispatch
,
state
,
rootState
,
rootGetters
},
{
data
},
{
data
,
branch
},
)
=>
{
)
=>
{
const
selectedProject
=
rootState
.
projects
[
rootState
.
currentProjectId
];
const
selectedProject
=
rootState
.
projects
[
rootState
.
currentProjectId
];
const
lastCommit
=
{
const
lastCommit
=
{
...
@@ -82,27 +93,15 @@ export const updateFilesAfterCommit = (
...
@@ -82,27 +93,15 @@ export const updateFilesAfterCommit = (
commit
(
rootTypes
.
REMOVE_ALL_CHANGES_FILES
,
null
,
{
root
:
true
});
commit
(
rootTypes
.
REMOVE_ALL_CHANGES_FILES
,
null
,
{
root
:
true
});
if
(
state
.
commitAction
===
consts
.
COMMIT_TO_NEW_BRANCH
)
{
if
(
state
.
commitAction
===
consts
.
COMMIT_TO_NEW_BRANCH
)
{
router
.
push
(
`/project/
${
rootState
.
currentProjectId
}
/blob/
branch
/
${
rootGetters
.
activeFile
.
path
}
`
);
router
.
push
(
`/project/
${
rootState
.
currentProjectId
}
/blob/
${
branch
}
/
${
rootGetters
.
activeFile
.
path
}
`
);
}
}
window
.
scrollTo
(
0
,
0
);
dispatch
(
'
updateCommitAction
'
,
consts
.
COMMIT_TO_CURRENT_BRANCH
);
dispatch
(
'
updateCommitAction
'
,
consts
.
COMMIT_TO_CURRENT_BRANCH
);
};
};
export
const
commitChanges
=
({
commit
,
state
,
getters
,
dispatch
,
rootState
})
=>
{
export
const
commitChanges
=
({
commit
,
state
,
getters
,
dispatch
,
rootState
})
=>
{
const
newBranch
=
state
.
commitAction
!==
consts
.
COMMIT_TO_CURRENT_BRANCH
;
const
newBranch
=
state
.
commitAction
!==
consts
.
COMMIT_TO_CURRENT_BRANCH
;
const
payload
=
{
const
payload
=
createCommitPayload
(
getters
.
branchName
,
newBranch
,
state
,
rootState
);
branch
:
getters
.
branchName
,
commit_message
:
state
.
commitMessage
,
actions
:
rootState
.
changedFiles
.
map
(
f
=>
({
action
:
f
.
tempFile
?
'
create
'
:
'
update
'
,
file_path
:
f
.
path
,
content
:
f
.
content
,
encoding
:
f
.
base64
?
'
base64
'
:
'
text
'
,
})),
start_branch
:
newBranch
?
rootState
.
currentBranchId
:
undefined
,
};
const
getCommitStatus
=
newBranch
?
Promise
.
resolve
(
false
)
:
dispatch
(
'
checkCommitStatus
'
);
const
getCommitStatus
=
newBranch
?
Promise
.
resolve
(
false
)
:
dispatch
(
'
checkCommitStatus
'
);
commit
(
types
.
UPDATE_LOADING
,
true
);
commit
(
types
.
UPDATE_LOADING
,
true
);
...
@@ -117,8 +116,6 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState }) =
...
@@ -117,8 +116,6 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState }) =
}))
}))
.
then
(()
=>
service
.
commit
(
rootState
.
currentProjectId
,
payload
))
.
then
(()
=>
service
.
commit
(
rootState
.
currentProjectId
,
payload
))
.
then
(({
data
})
=>
{
.
then
(({
data
})
=>
{
const
{
branch
}
=
payload
;
commit
(
types
.
UPDATE_LOADING
,
false
);
commit
(
types
.
UPDATE_LOADING
,
false
);
if
(
!
data
.
short_id
)
{
if
(
!
data
.
short_id
)
{
...
@@ -126,24 +123,20 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState }) =
...
@@ -126,24 +123,20 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState }) =
return
;
return
;
}
}
let
commitMsg
=
`Your changes have been committed. Commit
${
data
.
short_id
}
`
;
dispatch
(
'
setLastCommitMessage
'
,
data
);
if
(
data
.
stats
)
{
commitMsg
+=
` with
${
data
.
stats
.
additions
}
additions,
${
data
.
stats
.
deletions
}
deletions.`
;
}
commit
(
rootTypes
.
SET_LAST_COMMIT_MSG
,
commitMsg
,
{
root
:
true
});
if
(
state
.
commitAction
===
consts
.
COMMIT_TO_NEW_BRANCH_MR
)
{
if
(
state
.
commitAction
===
consts
.
COMMIT_TO_NEW_BRANCH_MR
)
{
const
selectedProject
=
rootState
.
projects
[
rootState
.
currentProjectId
];
dispatch
(
dispatch
(
'
redirectToUrl
'
,
'
redirectToUrl
'
,
`
${
selectedProject
.
web_url
}
/merge_requests/new?merge_request[source_branch]=
${
branch
}
&merge_request[target_branch]=
${
rootState
.
currentBranchId
}
`
,
createNewMergeRequestUrl
(
rootState
.
projects
[
rootState
.
currentProjectId
].
web_url
,
getters
.
branchName
,
rootState
.
currentBranchId
,
),
{
root
:
true
},
{
root
:
true
},
);
);
}
else
{
}
else
{
dispatch
(
'
updateFilesAfterCommit
'
,
{
data
,
branch
});
dispatch
(
'
updateFilesAfterCommit
'
,
{
data
,
branch
:
getters
.
branchName
});
}
}
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
...
@@ -153,5 +146,7 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState }) =
...
@@ -153,5 +146,7 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState }) =
}
}
flash
(
errMsg
,
'
alert
'
,
document
,
null
,
false
,
true
);
flash
(
errMsg
,
'
alert
'
,
document
,
null
,
false
,
true
);
window
.
dispatchEvent
(
new
Event
(
'
resize
'
));
window
.
dispatchEvent
(
new
Event
(
'
resize
'
));
commit
(
types
.
UPDATE_LOADING
,
false
);
});
});
};
};
app/assets/javascripts/ide/stores/utils.js
View file @
20dfb127
...
@@ -187,3 +187,18 @@ export const createOrMergeEntry = ({ projectId,
...
@@ -187,3 +187,18 @@ export const createOrMergeEntry = ({ projectId,
level
,
level
,
});
});
};
};
export
const
createCommitPayload
=
(
branch
,
newBranch
,
state
,
rootState
)
=>
({
branch
,
commit_message
:
state
.
commitMessage
,
actions
:
rootState
.
changedFiles
.
map
(
f
=>
({
action
:
f
.
tempFile
?
'
create
'
:
'
update
'
,
file_path
:
f
.
path
,
content
:
f
.
content
,
encoding
:
f
.
base64
?
'
base64
'
:
'
text
'
,
})),
start_branch
:
newBranch
?
rootState
.
currentBranchId
:
undefined
,
});
export
const
createNewMergeRequestUrl
=
(
projectUrl
,
source
,
target
)
=>
`
${
projectUrl
}
/merge_requests/new?merge_request[source_branch]=
${
source
}
&merge_request[target_branch]=
${
target
}
`
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment