Esempio n. 1
0
        public static int GetAnyWikiPageId(ClientSampleContext context, WikiV2 wiki)
        {
            string         path       = GetAnyWikiPagePath(context, wiki);
            VssConnection  connection = context.Connection;
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            WikiPage anyPage = wikiClient.GetPageAsync(
                project: wiki.ProjectId,
                wikiIdentifier: wiki.Id,
                path: path,
                recursionLevel: VersionControlRecursionType.OneLevel).SyncResult().Page;

            if (!anyPage.Id.HasValue)
            {
                WikiPageCreateOrUpdateParameters parameters = new WikiPageCreateOrUpdateParameters()
                {
                    Content = "Wiki page content"
                };

                WikiPageResponse wikiPageResponse = wikiClient.CreateOrUpdatePageAsync(
                    parameters,
                    project: wiki.ProjectId,
                    wikiIdentifier: wiki.Id,
                    path: "SamplePage" + new Random().Next(1, 999),
                    Version: null).SyncResult();

                context.Log("Create page '{0}' in wiki '{1}'", wikiPageResponse.Page.Path, wiki.Name);

                anyPage = wikiPageResponse.Page;
            }

            return(anyPage.Id.Value);
        }
Esempio n. 2
0
        public static string GetAnyWikiPagePath(ClientSampleContext context, WikiV2 wiki)
        {
            VssConnection  connection = context.Connection;
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            WikiPage rootPage = wikiClient.GetPageAsync(
                project: wiki.ProjectId,
                wikiIdentifier: wiki.Id,
                path: "/",
                recursionLevel: VersionControlRecursionType.OneLevel).SyncResult().Page;

            return(rootPage.SubPages[0].Path);
        }
Esempio n. 3
0
        public WikiPageResponse GetWikiPageMetadata()
        {
            VssConnection  connection = this.Context.Connection;
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            WikiV2 wiki         = Helpers.FindOrCreateProjectWiki(this.Context);
            string somePagePath = Helpers.GetAnyWikiPagePath(this.Context, wiki);

            WikiPageResponse somePageResponse = wikiClient.GetPageAsync(
                project: wiki.ProjectId,
                wikiIdentifier: wiki.Name,
                path: somePagePath).SyncResult();

            Context.Log("Retrieved page '{0}' metadata in wiki '{1}'", somePagePath, wiki.Name);

            return(somePageResponse);
        }
Esempio n. 4
0
        public WikiPageResponse GetWikiPageAndSubPages()
        {
            VssConnection  connection = this.Context.Connection;
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            WikiV2           wiki             = Helpers.FindOrCreateProjectWiki(this.Context);
            WikiPageResponse rootPageResponse = wikiClient.GetPageAsync(
                project: wiki.ProjectId,
                wikiIdentifier: wiki.Name,
                path: "/",
                recursionLevel: VersionControlRecursionType.OneLevel).SyncResult();

            Context.Log("Retrieved the following subpages for the root page:");
            foreach (WikiPage subPage in rootPageResponse.Page.SubPages)
            {
                Context.Log("Sub-page : '{0}'", subPage.Path);
            }

            return(rootPageResponse);
        }
Esempio n. 5
0
        public WikiPageResponse EditWikiPage()
        {
            VssConnection  connection = this.Context.Connection;
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            WikiV2 wiki         = Helpers.FindOrCreateProjectWiki(this.Context);
            string somePagePath = Helpers.GetAnyWikiPagePath(this.Context, wiki);

            WikiPageResponse pageResponse = wikiClient.GetPageAsync(
                project: wiki.ProjectId,
                wikiIdentifier: wiki.Name,
                path: somePagePath,
                includeContent: true).SyncResult();

            WikiPage somePage = pageResponse.Page;

            Context.Log("Retrieved page '{0}' as JSON in wiki '{1}' with content '{2}'", somePage.Path, wiki.Name, somePage.Content);

            var originalContent = somePage.Content;
            var originalVersion = pageResponse.ETag.ToList()[0];

            WikiPageCreateOrUpdateParameters parameters = new WikiPageCreateOrUpdateParameters()
            {
                Content = "New content for page"
            };

            WikiPageResponse editedPageResponse = wikiClient.CreateOrUpdatePageAsync(
                parameters: parameters,
                project: wiki.ProjectId,
                wikiIdentifier: wiki.Name,
                path: somePagePath,
                Version: originalVersion).SyncResult();

            var updatedContent = editedPageResponse.Page.Content;
            var updatedVersion = editedPageResponse.ETag.ToList()[0];

            Context.Log("Before editing --> Page path: {0}, version: {1}, content: {2}", somePage.Path, originalVersion, originalContent);
            Context.Log("After editing --> Page path: {0}, version: {1}, content: {2}", somePage.Path, updatedVersion, updatedContent);

            return(editedPageResponse);
        }
Esempio n. 6
0
        public async Task Run(string input, ILogger log)
#endif
        {
            string sb = await GenerateReleaseNotesMarkdown();

            string iterationName = await GetCurrentIterationName();

            using (WikiHttpClient wikiHttpClient = new WikiHttpClient(_uri, credentials))
            {
                try
                {
                    WikiPageResponse wikiPage = await wikiHttpClient.GetPageAsync(_project, _wikiName, $"/{iterationName}");

                    await wikiHttpClient.CreateOrUpdatePageAsync(new WikiPageCreateOrUpdateParameters()
                    {
                        Content = sb.ToString()
                    }, _project, _wikiName, $"/{iterationName}", wikiPage.ETag.First().ToString(), $"Updated on release notes on {DateTime.UtcNow}(UTC)");
                }
                catch (VssServiceException ex)
                {
                    /*
                     * What an ugly pattern to code with!
                     * Had to do this since the GetPageAsync call throws exception if page is not found.
                     * Hopefully, I fix this in the future.
                     */
                    log.LogInformation("Service exception raised. Assumed that the wiki page does not exist. Trying to create one.");
                    await wikiHttpClient.CreateOrUpdatePageAsync(new WikiPageCreateOrUpdateParameters()
                    {
                        Content = sb.ToString()
                    }, _project, _wikiName, $"/{iterationName}", null, $"Added release notes for {iterationName}");
                }
                catch
                {
                    throw;
                }
            }
            log.LogInformation("Completed execution. Please check your wiki for your release notes.");
        }