예제 #1
0
        private static CiEvent CreateScmEvent(CiEvent finishEvent, ScmData scmData)
        {
            var scmEventEvent = finishEvent.Clone();

            scmEventEvent.EventType = CiEventType.Scm;
            scmEventEvent.ScmData   = scmData;
            return(scmEventEvent);
        }
예제 #2
0
        public static ScmData GetScmData(TfsApis tfsManager, TfsBuildInfo buildInfo)
        {
            try
            {
                ScmData scmData         = null;
                var     originalChanges = tfsManager.GetBuildChanges(buildInfo.ProjectId, buildInfo.BuildId);
                if (originalChanges.Count > 0)
                {
                    var build = tfsManager.GetBuild(buildInfo.ProjectId, buildInfo.BuildId);
                    ICollection <TfsScmChange> filteredChanges = GetFilteredBuildChanges(tfsManager, buildInfo, build, originalChanges);
                    if (filteredChanges.Count > 0)
                    {
                        scmData = new ScmData();
                        var repository = tfsManager.GetRepositoryById(buildInfo.ProjectId, build.Repository.Id);
                        scmData.Repository        = new ScmRepository();
                        scmData.Repository.Branch = build.SourceBranch;
                        scmData.Repository.Type   = build.Repository.Type;
                        scmData.Repository.Url    = repository.RemoteUrl;

                        scmData.BuiltRevId = build.SourceVersion;
                        scmData.Commits    = new List <ScmCommit>();
                        foreach (TfsScmChange change in filteredChanges)
                        {
                            var       tfsCommit = tfsManager.GetCommitWithChanges(change.Location);
                            ScmCommit scmCommit = new ScmCommit();
                            scmData.Commits.Add(scmCommit);
                            scmCommit.User      = tfsCommit.Committer.Name;
                            scmCommit.UserEmail = tfsCommit.Committer.Email;
                            scmCommit.Time      = OctaneUtils.ConvertToOctaneTime(tfsCommit.Committer.Date);
                            scmCommit.RevId     = tfsCommit.CommitId;
                            if (tfsCommit.Parents.Count > 0)
                            {
                                scmCommit.ParentRevId = tfsCommit.Parents[0];
                            }

                            scmCommit.Comment = tfsCommit.Comment;
                            scmCommit.Changes = new List <ScmCommitFileChange>();

                            foreach (var tfsCommitChange in tfsCommit.Changes)
                            {
                                if (!tfsCommitChange.Item.IsFolder)
                                {
                                    ScmCommitFileChange commitChange = new ScmCommitFileChange();
                                    scmCommit.Changes.Add(commitChange);

                                    string commitChangeType = tfsCommitChange.ChangeType.ToLowerInvariant();
                                    switch (commitChangeType)
                                    {
                                    case "add":
                                    case "edit":
                                    case "delete":
                                        //do nothins
                                        break;

                                    case "delete, sourcerename":
                                        commitChangeType = "delete";
                                        break;

                                    case "rename":
                                    case "edit, rename":
                                        commitChangeType = "add";
                                        break;

                                    default:
                                        Log.Debug($"Build {buildInfo} - Unexpected change type <{commitChangeType}> for file <{tfsCommitChange.Item.Path}>. Setting default to 'edit'.");
                                        commitChangeType = "edit";

                                        break;
                                    }

                                    commitChange.Type = commitChangeType;
                                    commitChange.File = tfsCommitChange.Item.Path;
                                }
                            }
                        }
                    }
                }
                return(scmData);
            }
            catch (Exception e)
            {
                Log.Error($"Build {buildInfo} - failed to create scm data : {e.Message}");
                return(null);
            }
        }