             else
                 return true
 
+        retrieveLatestCommits = (builder) ->
+            data.getBuilds(limit: 50, order: '-complete_at', builderid: builder.builderid, complete: 'true', results: 0).onChange = (builds) ->
+                for build in builds
+                    build.getProperties().onNew = (properties) ->
+                        if properties['branch']?
+                            # NOT GIT tagged versions - 'post-commit' stages candidates
+                            if not properties['branch'][0].match(/tags/)
+                                projectName = properties['codebase'][0]
+                                if properties['revision']?
+                                    for version in $scope.untaggedVersionsByProject
+                                        if projectName == version.projectName and properties['revision'][0] not in version.versions
+                                            new_version = properties['revision'][0]
+                                            version.versions.push(new_version)
+                                    $scope.untaggedVersionsByProjectDict = $scope.untaggedVersionsByProject.toDict('projectName')
+
+                            # GIT tagged versions
+                            if properties['branch'][0].match(/tags/)
+                                projectName = properties['codebase'][0]
+                                if properties['commit-description']?
+                                    for g in gitTagsByProject
+                                       if projectName == g.projectName
+                                            if properties['commit-description'][0] not in g.projectGitTags
+                                                new_version = []
+                                                new_version = properties['commit-description'][0]
+                                                if g.projectGitTags[0] == 'NA'
+                                                    g.projectGitTags = []
+                                                if new_version[projectName] not in g.projectGitTags
+                                                    g.projectGitTags.push(new_version[projectName])
+                                                for r in gitTagRevisionMap
+                                                    if projectName == r.projectName
+                                                        new_entry_map = {}
+                                                        new_entry_map.tag = properties['commit-description'][0][projectName]
+                                                        new_entry_map.rev = properties['got_revision'][0][projectName]
+                                                        r.map.push(new_entry_map)
+                                                gitTagRevisionMapDict = gitTagRevisionMap.toDict('projectName')
+                                    $scope.gitTagsByProjectDict = gitTagsByProject.toDict('projectName')
+
+
+        retrieveDeployedVersions = (builder) ->
+            data.getBuilds(limit: 50, order: '-complete_at', builderid: builder.builderid, complete: 'true', results: 0).onChange = (builds) ->
+                for build in builds
+                    build.getProperties().onNew = (properties) ->
+                        if properties?
+                            projectName = properties['codebase'][0]
+                            # With a defined version property (ie commit has been GIT tagged)
+                            if properties['version'][0]? and properties['version'][0] != ''
+                                if properties['stage'][0]? and properties['stage'][0] != ''
+                                    if latestDeployedVersionByProject != []
+                                        for p in latestDeployedVersionByProject
+                                            if p.projectName == projectName
+                                                for s in p.stages
+                                                    if s.stage == properties['stage'][0] and s.versions[0] == 'NA'
+                                                        s.versions = []
+                                                        s.versions.push(properties['version'][0])
+                                                    else
+                                                        new_version = properties['version'][0]
+                                                        if new_version not in s.versions
+                                                            s.versions.push(new_version)
+                                                stage_info = {}
+                                                stage_info = p.stages.toDict('stage')
+                                                p.stages_sorted = stage_info
+                                        $scope.latestDeployedVersionByProjectDict = latestDeployedVersionByProject.toDict('projectName')
+                            # Without a defined version property (ie commit has not been GIT tagged yet, GIT tag is generated by the deploy build)
+                            else if properties['revision'][0]? and properties['revision'][0] != '' and properties['version'][0] == ''
+                                if properties['stage'][0]? and properties['stage'][0] != ''
+                                    if latestDeployedVersionByProject != []
+                                        for p in latestDeployedVersionByProject
+                                            if p.projectName == projectName
+                                                for x in gitTagRevisionMapDict[projectName].map
+                                                    if x.rev == properties['revision'][0]
+                                                        for s in p.stages
+                                                            if s.stage == properties['stage'][0] and s.versions[0] == 'NA'
+                                                                s.versions = []
+                                                                s.versions.push(x.tag)
+                                                            else
+                                                                new_version = x.tag
+                                                                if new_version not in s.versions
+                                                                    s.versions.push(new_version)
+                                                        stage_info = {}
+                                                        stage_info = p.stages.toDict('stage')
+                                                        p.stages_sorted = stage_info
+                                        $scope.latestDeployedVersionByProjectDict = latestDeployedVersionByProject.toDict('projectName')
+
         retrieveInfo = ->
             # Retrieve the commit-description properties that contain ALL the versions (tagged or not)
             # First case : dev have been successfully merged, ready to be deployed in 'post commit' stages - not GIT tagged yet
             # Second case : dev have been deployed in 'post commit' stages - GIT tagged
             data.getBuilders().onNew = (builder) ->
-                console.log 'Retrieving the builders'
                 name = ''
                 name = builder.name
 
                 for p, k in $scope.projectsFiltered
-
                     if name.match(p.name)
                         if not name.match(/-deploy/) and not name.match(/-job/) and not name.match(/-try/)
-                            data.getBuilds(limit: 50, order: '-complete_at', builderid: builder.builderid, complete: 'true', results: 0).onChange = (builds) ->
-                                console.log 'Retrieving the builds...'
-                                for build in builds
-                                    build.getProperties().onNew = (properties) ->
-                                        if properties['branch']?
-                                            # NOT GIT tagged versions - 'post-commit' stages candidates
-                                            if not properties['branch'][0].match(/tags/)
-                                                projectName = properties['codebase'][0]
-
-                                                if properties['revision']?
-
-                                                    for version in $scope.untaggedVersionsByProject
-                                                        if projectName == version.projectName
-                                                            if properties['revision'][0] not in version.versions
-                                                                new_version = properties['revision'][0]
-                                                                version.versions.push(new_version)
-                                                    $scope.untaggedVersionsByProjectDict = $scope.untaggedVersionsByProject.toDict('projectName')
-
-                                            # GIT tagged versions
-                                            if properties['branch'][0].match(/tags/)
-                                                projectName = properties['codebase'][0]
-                                                if properties['commit-description']?
-                                                    for g in gitTagsByProject
-                                                       if projectName == g.projectName
-                                                            if properties['commit-description'][0] not in g.projectGitTags
-                                                                new_version = []
-                                                                new_version = properties['commit-description'][0]
-                                                                if g.projectGitTags[0] == 'NA'
-                                                                    g.projectGitTags = []
-                                                                if new_version[projectName] not in g.projectGitTags
-                                                                    g.projectGitTags.push(new_version[projectName])
-                                                    $scope.gitTagsByProjectDict = gitTagsByProject.toDict('projectName')
+                            retrieveLatestCommits(builder)
 
                         else if name.match(/-deploy/)
-                            data.getBuilds(limit: 50, order: '-complete_at', builderid: builder.builderid, complete: 'true', results: 0).onChange = (builds) ->
-                                console.log 'Retrieving the deploy builds...'
-                                for build in builds
-                                    build.getProperties().onNew = (properties) ->
-                                        if properties?
-                                            projectName = properties['codebase'][0]
-
-                                            if properties['version'][0]? and properties['version'][0] != ''
-                                                if properties['stage'][0]? and properties['stage'][0] != ''
-                                                    if latestDeployedVersionByProject != []
-                                                        for p in latestDeployedVersionByProject
-                                                            if p.projectName == projectName
-                                                                for s in p.stages
-                                                                    if s.stage == properties['stage'][0]
-                                                                        if s.versions[0] == 'NA'
-                                                                            s.versions = []
-                                                                            s.versions.push(properties['version'][0])
-                                                                        else
-                                                                            new_version = properties['version'][0]
-                                                                            if new_version not in s.versions
-                                                                                s.versions.push(properties['version'][0])
-                                                                stage_info = {}
-                                                                stage_info = p.stages.toDict('stage')
-                                                                p.stages_sorted = stage_info
-                                                        $scope.latestDeployedVersionByProjectDict = latestDeployedVersionByProject.toDict('projectName')
-
-
+                            retrieveDeployedVersions(builder)
 
                         else
                             return
 
-
         filterProjects()
-        initVersions()
-
+        initMappingBuildGitData()
         retrieveInfo()
-
-        $scope.submit = ->
-            console.log $scope.selectedTag
-            console.log $scope.selectedProject
-            console.log $scope.selectedStage
-            console.log $scope.builderName
-
 
         $scope.deploy = (tag, project, stage) ->
             $scope.selectedTag = tag

        $scope.projectsFiltered = []
        latestDeployedVersionByProject = []
        gitTagsByProject = []
        data = []

        # We need access to the deliverables names / stages / GIT tags / commit-description property

                $scope.fscheduler = forcesched
                $scope.builderName = project + '-deploy'

                modal = {}
                modal.modal = $uibModal.open
                    templateUrl: 'buildbot_travis/views/deploy_latest_dialog.html'
