示例#1
0
        /// <inheritdoc/>
        public override async Task RunAsync(CommandLine commandLine)
        {
            if (commandLine.HasHelpOption)
            {
                Help();
                return;
            }

            var repoArg = commandLine.Arguments.ElementAtOrDefault(0);
            var nameArg = commandLine.Arguments.ElementAtOrDefault(1);
            var ageArg  = commandLine.GetOption("--max-age-days", "0");

            if (string.IsNullOrEmpty(repoArg))
            {
                Console.Error.WriteLine("*** ERROR: [REPO] argument is required.");
                Program.Exit(1);
            }

            var repoPath     = GitHubRepoPath.Parse(repoArg);
            var workflowName = nameArg;
            var maxAge       = TimeSpan.FromDays(Math.Max(int.Parse(ageArg), 0));
            var deleted      = await GitHub.Actions.DeleteRunsAsync(repoPath.ToString(), workflowName, maxAge);

            Console.WriteLine();
            Console.WriteLine($"[{deleted}] workflow runs deleted");
            Console.WriteLine();
        }
示例#2
0
        //---------------------------------------------------------------------
        // Static members

        /// <summary>
        /// Parses a GitHub repository path.
        /// </summary>
        /// <param name="path">The path, like: <b>[SERVER]/OWNER/REPO</b></param>
        /// <returns>The parsed <see cref="GitHubRepoPath"/>.</returns>
        /// <exception cref="FormatException">Thrown when the input is invalid.</exception>
        /// <remarks>
        /// <note>
        /// <b>github.com</b> will be assumed when no server is specified.
        /// </note>
        /// </remarks>
        public static GitHubRepoPath Parse(string path)
        {
            Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(path), nameof(path));

            var parts = path.Split('/');

            foreach (var part in parts)
            {
                if (part.Length == 0 || part.Contains(' '))
                {
                    throw new FormatException($"Invalid GitHub repo path: {path}");
                }
            }

            var repoPath = new GitHubRepoPath();

            switch (parts.Length)
            {
            case 2:

                repoPath.Server = "github.com";
                repoPath.Owner  = parts[0];
                repoPath.Repo   = parts[1];
                break;

            case 3:

                repoPath.Server = parts[0];
                repoPath.Owner  = parts[1];
                repoPath.Repo   = parts[2];
                break;

            default:

                throw new FormatException($"Invalid GitHub repo path: {path}");
            }

            return(repoPath);
        }