Permalink
Browse files

remove git clone from controller (to be added to build manager); add …

…ability to run BuildProcess in a specified directory
  • Loading branch information...
1 parent 840e18a commit 5fe39b4c0dc3cc0c0544d6d65aec93a9f01abb01 David Vollbracht committed Nov 18, 2008
Showing with 78 additions and 25 deletions.
  1. +0 −4 app/AdminController.io
  2. +18 −5 app/BuildProcess.io
  3. +3 −0 app/GitRepository.io
  4. +8 −0 app/Project.io
  5. +3 −3 stories
  6. +2 −11 test/AdminTest.io
  7. +13 −1 test/BuildProcessTest.io
  8. +14 −1 test/GitRepositoryTest.io
  9. +17 −0 test/ProjectTest.io
@@ -2,15 +2,11 @@ AdminController := Controller clone do (
projects := method(objStore projects)
handleRequest := method(request, response,
- application projectDirectory createIfAbsent
-
if (request requestMethod == "POST",
project := Project clone setName(request parameters at("name")) \
setUrl(request parameters at("uri")) \
setBuildCommand(request parameters at("buildCommand"))
- newRepo := GitRepository at(application projectDirectory directoryNamed(project name))
- newRepo gitClone(project url)
objStore save(project)
)
View
@@ -1,24 +1,37 @@
BuildProcess := Object clone do(
newSlot("command")
+ newSlot("directory", Directory with(Directory currentWorkingDirectory))
newSlot("started", false)
- newSlot("file", nil)
newSlot("exitStatus", nil)
+ init := method(
+ resend
+ self output := "" asMutable
+ )
+
start := method(
self systemCall := SystemCall clone
- if(command,
- setFile(File clone setPath(command)) @@build
- ,
- setExitStatus(1))
+ if(command, @@build, setExitStatus(1))
setStarted(true)
)
build := method(
+ file := File clone setPath("cd " .. directory path .. " && " .. command)
+ # streamTo recalls open, which resets the flags as causes pclose
+ # to never be called and we don't get an exit status
+ #
+ file open = nil
file popen
+ file streamTo(Receiver clone setTarget(self))
file close
setExitStatus(file exitStatus)
)
+ Receiver := Object clone do (
+ newSlot("target")
+ write := method(s, target output appendSeq(s))
+ )
+
isRunning := method(started and exitStatus isNil)
isSuccessful := method(isRunning not and exitStatus == 0)
)
@@ -9,6 +9,7 @@ GitRepository := Object clone do (
)
gitClone := method(masterUri,
+ if(directory exists, return self)
gitDo(directory parentDirectory, "clone", masterUri, directory name)
)
@@ -28,6 +29,8 @@ GitRepository := Object clone do (
command := "cd '#{directory path}' && git #{gitCommand} #{argumentsString} > /dev/null 2>&1" interpolate
logCommand(command)
(System system(command) == 0) ifFalse(Exception raise(command .. " failed"))
+
+ self
)
logCommand := method(nil)
View
@@ -1,5 +1,13 @@
Project := StoredObject clone do (
storedFields("name", "url", "buildCommand")
+ newSlot("gitRepositoryProto")
newBuild := method(Build clone setProject(self))
+
+ newClonedRepositoryIn := method(directory,
+ repo := gitRepositoryProto clone setDirectory(
+ directory directoryNamed(name)
+ )
+ repo gitClone(url)
+ )
)
View
@@ -2,18 +2,18 @@ Admin
x * Add a project
* Remove a project
x * Remember projects across restarts
- * Configure a build task
+x * Configure a build task
* Display origin url for existing projects
* Limit admin access based on username/password
* Edit an existing project
Git Support
-x * Clone repository on add
+ * Clone repository on add
* Delete repository on remove
* Check for changes and pull
Building
- * Run project build task immediately after add
+x * Run project build task immediately after add
* Run project build task after pull
* Report successful run of build task
* Report unsuccessful run of build task
View
@@ -25,39 +25,30 @@ IcisAppTest clone do (
)
testIndexAfterAddingProjectsDisplaysProjectsWithNames := method (
- repo := GitRepository at(TempDirectory testDir directoryNamed("repo"))
- repo gitInit
-
response := get("/admin")
projectForm := response page at("projectForm")
projectForm input("name") set("Project 1")
- projectForm input("uri") set(repo directory path)
submit(projectForm)
response := get("/admin")
projects := response page findElements(class == "project")
assertEquals(1, projects size)
- assertEquals(repo directory path,
- GitRepository at(application projectDirectory directoryNamed("Project 1")) originUrl)
)
testAddingProjectCreatesProjectWithAllFields := method (
- repo := GitRepository at(TempDirectory testDir directoryNamed("repo"))
- repo gitInit
-
response := get("/admin")
projectForm := response page at("projectForm")
projectForm input("name") set("Project 1")
- projectForm input("uri") set(repo directory path)
+ projectForm input("uri") set("repopath")
projectForm input("buildCommand") set("doit")
submit(projectForm)
assertEquals(1, objStore projects size)
assertEquals("Project 1", objStore projects first name)
- assertEquals(repo directory path, objStore projects first url)
+ assertEquals("repopath", objStore projects first url)
assertEquals("doit", objStore projects first buildCommand)
)
)
@@ -29,7 +29,19 @@ UnitTest clone do (
waitFor(build isRunning not)
assertFalse(build isSuccessful)
)
-
+
+ testBuildProcessCollectsOutputFromRun := method(
+ build := BuildProcess clone setCommand("echo hello") start
+ waitFor(build isRunning not)
+ assertEquals("hello\n", build output)
+ )
+
+ testBuildProcessRunsInRequestedDirectory := method(
+ build := BuildProcess clone setDirectory(TempDirectory) setCommand("pwd") start
+ waitFor(build isRunning not)
+ assertEquals(TempDirectory path .. "\n", build output)
+ )
+
waitFor := method(
startTime := Date now
while(startTime secondsSinceNow < 1 and call evalArgAt(0) not, yield)
@@ -14,12 +14,25 @@ UnitTest clone do (
masterRepo gitInit
# Git doesn't like to clone without a commit
masterRepo gitDo(masterRepo directory, "commit", "--allow-empty", "-m", "test")
- cloneRepo gitClone(masterRepo directory path)
+ assertEquals(cloneRepo, cloneRepo gitClone(masterRepo directory path))
assertTrue(cloneRepo directory exists)
assertEquals(masterRepo directory path, cloneRepo originUrl)
)
+ testCloningAGitRepositoryTwiceIsHarmless := method(
+ masterRepo := GitRepository at(TempDirectory testDir directoryNamed("master repo"))
+ cloneRepo := GitRepository at(TempDirectory testDir directoryNamed("clone repo"))
+
+ masterRepo gitInit
+ # Git doesn't like to clone without a commit
+ masterRepo gitDo(masterRepo directory, "commit", "--allow-empty", "-m", "test")
+
+ 2 repeat(
+ assertEquals(cloneRepo, cloneRepo gitClone(masterRepo directory path))
+ )
+ )
+
testGitDoRaisesExceptionIfCommandFails := method(
repo := GitRepository at(TempDirectory testDir)
repo gitInit
View
@@ -1,6 +1,11 @@
Lobby doRelativeFile("TestHelper.io")
UnitTest clone do (
+ FakeGitRepository := GitRepository clone do (
+ newSlot("clonedFromUrl")
+ gitClone := method(url, setClonedFromUrl(url))
+ )
+
testProjectCreateNewBuildsWithItsId := method(
objStore := ObjectStore clone setPath(TempDirectory testFile path)
@@ -9,4 +14,16 @@ UnitTest clone do (
assertEquals(project id, project newBuild projectId)
)
+
+ testProjectClonesGitRepoIntoSpecifiedDirectory := method(
+ testDir := TempDirectory testDir
+
+ project := Project clone setName("TestProject") \
+ setGitRepositoryProto(FakeGitRepository) \
+ setUrl("repouri")
+
+ repo := project newClonedRepositoryIn(testDir)
+ assertEquals("repouri", repo clonedFromUrl)
+ assertEquals(testDir directoryNamed("TestProject") path, repo directory path)
+ )
)

0 comments on commit 5fe39b4

Please sign in to comment.