Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb56993a

Browse files
committed
get last passing commit hash
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parentf6c861f commitb56993a

File tree

5 files changed

+89
-16
lines changed

5 files changed

+89
-16
lines changed

‎src/channel/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { openWorkspace, checkWorkspaceEmpty } from '../services/workspace'
1818
import{showOutput}from'../services/testRunner/output'
1919
import{exec}from'../services/node'
2020
import{WORKSPACE_ROOT,TUTORIAL_URL}from'../environment'
21+
importgetLastCommitHashfrom'../services/git/lastHash'
2122

2223
constreadFileAsync=promisify(readFile)
2324

@@ -322,11 +323,16 @@ class Channel implements Channel {
322323
return
323324
case'EDITOR_RUN_RESET':
324325
// reset to timeline
325-
// 1. get last pass commit
326-
// 2. load timeline until last pass commit
326+
consttutorial:TT.Tutorial|null=this.context.tutorial.get()
327+
constposition:T.Position=this.context.position.get()
328+
329+
// get last pass commit
330+
consthash=getLastCommitHash(position,tutorial?.levels||[])
331+
332+
// load timeline until last pass commit
333+
// TODO: run reset script
327334

328335
// if tutorial.config.reset.command, run it
329-
consttutorial:TT.Tutorial|null=this.context.tutorial.get()
330336
if(tutorial?.config?.reset?.command){
331337
awaitexec({command:tutorial.config.reset.command})
332338
}

‎src/services/git/lastHash.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import*asTTfrom'../../../typings/tutorial'
2+
import*asTfrom'../../../typings'
3+
importgetLastCommitHashfrom'./lastHash'
4+
5+
describe('lastHash',()=>{
6+
it('should grab the last passing hash from a step',()=>{
7+
constposition:T.Position={levelId:'1',stepId:'1.2'}
8+
constlevels:TT.Level[]=[
9+
{
10+
id:'1',
11+
title:'',
12+
summary:'',
13+
content:'',
14+
steps:[
15+
{
16+
id:'1.1',
17+
content:'',
18+
setup:{commits:['abcdef1']},
19+
},
20+
{
21+
id:'1.2',
22+
content:'',
23+
setup:{commits:['abcdef2']},
24+
},
25+
],
26+
},
27+
]
28+
constresult=getLastCommitHash(position,levels)
29+
expect(result).toBe('abcdef2')
30+
})
31+
it('should grab the last passing hash from a step with several commits',()=>{
32+
constposition:T.Position={levelId:'1',stepId:'1.2'}
33+
constlevels:TT.Level[]=[
34+
{
35+
id:'1',
36+
title:'',
37+
summary:'',
38+
content:'',
39+
steps:[
40+
{
41+
id:'1.1',
42+
content:'',
43+
setup:{commits:['abcdef1']},
44+
},
45+
{
46+
id:'1.2',
47+
content:'',
48+
setup:{commits:['abcdef2','abcdef3']},
49+
},
50+
],
51+
},
52+
]
53+
constresult=getLastCommitHash(position,levels)
54+
expect(result).toBe('abcdef3')
55+
})
56+
})

‎src/services/git/lastHash.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import*asTTfrom'../../../typings/tutorial'
2+
import*asTfrom'../../../typings'
3+
4+
constgetLastCommitHash=(position:T.Position,levels:TT.Level[])=>{
5+
// get previous position
6+
const{ levelId, stepId}=position
7+
8+
constlevel:TT.Level|undefined=levels.find((l)=>levelId===l.id)
9+
if(!level){
10+
thrownewError(`No level found matching${levelId}`)
11+
}
12+
conststep=level.steps.find((s)=>stepId===s.id)
13+
if(!step){
14+
thrownewError(`No step found matching${stepId}`)
15+
}
16+
constcommits=step.setup.commits
17+
if(!commits.length){
18+
thrownewError(`No commits found on step${stepId}`)
19+
}
20+
returncommits[commits.length-1]
21+
}
22+
23+
exportdefaultgetLastCommitHash

‎src/services/git/lastPass.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎typings/tutorial.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export type Step = {
3434
id:string
3535
content:string
3636
setup:StepActions
37-
solution:Maybe<StepActions>
37+
solution?:Maybe<StepActions>
3838
hints?:string[]
3939
subtasks?:string[]
4040
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp