src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt

changeset 284
671c1c8fbf1c
parent 271
f8f5e82944fa
child 292
703591e739f4
     1.1 --- a/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt	Sat Jul 22 15:07:23 2023 +0200
     1.2 +++ b/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt	Sat Jul 22 22:32:04 2023 +0200
     1.3 @@ -46,6 +46,7 @@
     1.4          get("/%project/edit", this::projectForm)
     1.5          get("/-/create", this::projectForm)
     1.6          post("/-/commit", this::projectCommit)
     1.7 +        post("/%project/vcs/analyze", this::vcsAnalyze)
     1.8  
     1.9          get("/%project/versions/", this::versions)
    1.10          get("/%project/versions/%version/edit", this::versionForm)
    1.11 @@ -243,6 +244,7 @@
    1.12              description = http.param("description") ?: ""
    1.13              ordinal = http.param("ordinal")?.toIntOrNull() ?: 0
    1.14              repoUrl = http.param("repoUrl") ?: ""
    1.15 +            vcs = VcsType.valueOf(http.param("vcs") ?: "None")
    1.16              owner = (http.param("owner")?.toIntOrNull() ?: -1).let {
    1.17                  if (it < 0) null else dao.findUser(it)
    1.18              }
    1.19 @@ -261,6 +263,26 @@
    1.20          http.renderCommit("projects/${project.node}")
    1.21      }
    1.22  
    1.23 +    private fun vcsAnalyze(http: HttpRequest, dao: DataAccessObject) {
    1.24 +        val projectInfo = obtainProjectInfo(http, dao)
    1.25 +        if (projectInfo == null) {
    1.26 +            http.response.sendError(404)
    1.27 +            return
    1.28 +        }
    1.29 +
    1.30 +        // if analysis is not configured, reject the request
    1.31 +        if (projectInfo.project.vcs == VcsType.None) {
    1.32 +            http.response.sendError(404)
    1.33 +            return
    1.34 +        }
    1.35 +
    1.36 +        // obtain the list of issues for this project to filter cross-project references
    1.37 +        val knownIds = dao.listIssues(projectInfo.project, true).map { it.id }
    1.38 +
    1.39 +        // read the provided commit log and merge only the refs that relate issues from the current project
    1.40 +        dao.mergeCommitRefs(parseCommitRefs(http.body).filter { knownIds.contains(it.issueId) })
    1.41 +    }
    1.42 +
    1.43      private fun versions(http: HttpRequest, dao: DataAccessObject) {
    1.44          val projectInfo = obtainProjectInfo(http, dao)
    1.45          if (projectInfo == null) {
    1.46 @@ -475,7 +497,8 @@
    1.47                      component,
    1.48                      dao.listIssues(project, true),
    1.49                      dao.listIssueRelations(issue),
    1.50 -                    relationError
    1.51 +                    relationError,
    1.52 +                    dao.listCommitRefs(issue)
    1.53                  )
    1.54                  feedPath = feedPath(projectInfo.project)
    1.55                  navigationMenu = activeProjectNavMenu(

mercurial