public Message ToSlackMessage(BuildCompletionNotification notification, BotElement bot, string channel)
        {
            var lines = notification.ToMessage(bot, s => s);
            var color = notification.IsSuccessful ? bot.GetSetting("successColor") : bot.GetSetting("errorColor");

            return(SlackHelper.CreateSlackMessage(lines, bot, channel, color));
        }
示例#2
0
        protected override IEnumerable <INotification> CreateNotifications(TeamFoundationRequestContext requestContext, BuildCompletionNotificationEvent buildNotification, int maxLines)
        {
            BuildDetail build           = buildNotification.Build;
            var         locationService = requestContext.GetService <ILocationService>();
            var         buildService    = requestContext.GetService <TeamFoundationBuildService>();

            using (var buildReader = buildService.QueryQueuedBuildsById(requestContext, build.QueueIds, new[] { "*" }, QueryOptions.None))
            {
                var         result   = buildReader.Current <BuildQueueQueryResult>();
                QueuedBuild qb       = result.QueuedBuilds.FirstOrDefault();
                string      buildUrl = string.Format("{0}/{1}/{2}/_build#_a=summary&buildId={3}",
                                                     locationService.GetAccessMapping(requestContext, "PublicAccessMapping").AccessPoint,
                                                     requestContext.ServiceHost.Name, build.TeamProject, qb.BuildId);

                var notification = new BuildCompletionNotification()
                {
                    TeamProjectCollection = requestContext.ServiceHost.Name,
                    BuildUrl                = buildUrl,
                    ProjectName             = build.TeamProject,
                    BuildNumber             = build.BuildNumber,
                    BuildStatus             = build.Status,
                    BuildReason             = build.Reason,
                    StartTime               = build.StartTime,
                    FinishTime              = build.FinishTime,
                    RequestedForUniqueName  = qb.RequestedFor,
                    RequestedForDisplayName = qb.RequestedForDisplayName,
                    BuildDefinition         = build.Definition.Name,
                    DropLocation            = build.DropLocation,
                    TeamNames               = GetUserTeamsByProjectName(requestContext, build.TeamProject, qb.RequestedFor)
                };

                yield return(notification);
            }
        }
        public Message ToSlackMessage(BuildCompletionNotification notification, BotElement bot, string channel)
        {
            var lines = notification.ToMessage(bot, s => s);
            var color = notification.IsSuccessful ? bot.GetSetting("successColor") : bot.GetSetting("errorColor");

            return SlackHelper.CreateSlackMessage(lines, bot, channel, color);
        }
示例#4
0
        internal static Message CreateMsTeamsMessage(BuildCompletionNotification notification, BotElement bot)
        {
            var lines = notification.ToMessage(bot, s => s);

            if (lines == null || !lines.Any())
            {
                return(null);
            }

            string color = notification.IsPartiallySucceeded ? bot.GetSetting("partiallySucceededColor") : (notification.IsSuccessful ? bot.GetSetting("successColor") : bot.GetSetting("errorColor"));

            return(CreateMsTeamsMessage(lines[0], new[] { new Fact(bot.Text.BuildStatus, $"**{lines[1]}**") }, color));
        }
示例#5
0
        private string ToJson(BuildCompletionNotification notification, BotElement bot)
        {
            var color = notification.IsSuccessful ? bot.GetSetting("successColor") : bot.GetSetting("errorColor");

            return(CreateHipChatMessage(notification, bot, color).ToString());
        }
        public async Task NotifyAsync(TeamFoundationRequestContext requestContext, INotification notification, BotElement bot, EventRuleElement matchingRule)
        {
            string URL        = bot.GetSetting("spiraURL");
            string user       = bot.GetSetting("spiraUser");
            string password   = bot.GetSetting("spiraPassw");
            string projVers   = bot.GetSetting("spiraPvers");
            string projNumber = bot.GetSetting("spiraPnumber");
            int    status     = 0;
            int    projectId;

            Int32.TryParse(projNumber, out projectId);

            //Check that it is the correct kind of notification
            if (notification is BuildCompletionNotification)
            {
                BuildCompletionNotification buildCompletionNotification = (BuildCompletionNotification)notification;

                if (buildCompletionNotification.IsSuccessful)
                {
                    status = 2;  //sucess
                }
                else if (buildCompletionNotification.BuildStatus.ToString() == "Failed")
                {
                    status = 1; //failed
                }
                else if (buildCompletionNotification.BuildStatus.ToString() == "PartiallySucceeded")
                {
                    status = 3; //unstable
                }
                else if (buildCompletionNotification.BuildStatus.ToString() == "Stopped")
                {
                    status = 4; //aborted
                }
                else
                {
                    TeamFoundationApplicationCore.Log(requestContext, ":: SpiraTeam Plugin for TFS:: The current build finished with a not supported" +
                                                      " status, please check TFS logs to see detailed information.", 0, EventLogEntryType.Warning);
                }


                DateTime date        = buildCompletionNotification.StartTime;
                String   sname       = buildCompletionNotification.ProjectName + " #" + buildCompletionNotification.BuildNumber;
                String   description = ("Information retrieved from TFS : Build requested by " +
                                        buildCompletionNotification.UserName + "<br/> from Team " +
                                        buildCompletionNotification.TeamNames + "<br/> and project collection " +
                                        buildCompletionNotification.TeamProjectCollection + "<br/> for " + sname +
                                        "<br/> with URL " + buildCompletionNotification.BuildUrl +
                                        "<br/> located at " + buildCompletionNotification.DropLocation +
                                        "<br/> Build Started at " + buildCompletionNotification.StartTime +
                                        "<br/> Build finished at " + buildCompletionNotification.FinishTime +
                                        "<br/> Status " + buildCompletionNotification.BuildStatus);
                //List<int> incidentIds;
                var    locationService = requestContext.GetService <TeamFoundationLocationService>();
                string baseUrl         = String.Format("{0}/", locationService.GetAccessMapping(requestContext,
                                                                                                "PublicAccessMapping").AccessPoint);
                TfsTeamProjectCollection tpc           = new TfsTeamProjectCollection(new Uri(baseUrl));
                VersionControlServer     sourceControl = tpc.GetService <VersionControlServer>();
                int revisionId = sourceControl.GetLatestChangesetId();

                //SPIRA CODE
                Uri uri = new Uri(URL + URL_SUFFIX);
                ImportExportClient spiraClient = SpiraClientFactory.CreateClient(uri);
                bool success = spiraClient.Connection_Authenticate2(user, password, "TFS Notifier for SpiraTeam v. 1.0.0");
                if (!success)
                {
                    TeamFoundationApplicationCore.Log(requestContext, ":: SpiraTeam Plugin for TFS :: Unable to connect to the Spira server, please verify" +
                                                      " the provided information in the configuration file.", 0, EventLogEntryType.Error);
                }
                success = spiraClient.Connection_ConnectToProject(projectId);
                if (!success)
                {
                    TeamFoundationApplicationCore.Log(requestContext, ":: SpiraTeam Plugin for TFS :: The project Id you specified either does not exist," +
                                                      "or your user does not have access to it! Please verify the configuration file.", 0, EventLogEntryType.Error);
                }

                RemoteRelease[] releases = spiraClient.Release_Retrieve(true);
                RemoteRelease   release  = releases.FirstOrDefault(r => r.VersionNumber == projVers);
                if (release != null)
                {
                    List <RemoteBuildSourceCode> revisions = new List <RemoteBuildSourceCode>();
                    RemoteBuildSourceCode        revision  = new RemoteBuildSourceCode();
                    revision.RevisionKey = revisionId.ToString();
                    revisions.Add(revision);

                    RemoteBuild newBuild = new RemoteBuild();
                    newBuild.Name          = sname;
                    newBuild.BuildStatusId = status;
                    newBuild.Description   = description;
                    newBuild.CreationDate  = date;
                    newBuild.Revisions     = revisions.ToArray();
                    newBuild.ReleaseId     = release.ReleaseId.Value;
                    spiraClient.Build_Create(newBuild);
                    await Task.Delay(10);
                }
                else
                {
                    TeamFoundationApplicationCore.Log(requestContext, ":: SpiraTeam Plugin for TFS :: The release version number you specified does not " +
                                                      "exist in the current project! Please verify the configuration file.", 0, EventLogEntryType.Error);
                }
            }
        }
        private string ToJson(BuildCompletionNotification notification, BotElement bot)
        {
            var color = notification.IsSuccessful ? bot.GetSetting("successColor") : bot.GetSetting("errorColor");

            return CreateHipChatMessage(notification, bot, color).ToString();
        }