Ejemplo n.º 1
0
        /// <summary>
        /// Creates a mock <see cref="IClient"/> that returns a specific <see cref="ITGRepository"/> when that component is requested
        /// </summary>
        /// <param name="repo">The <see cref="ITGRepository"/> the resulting <see cref="IClient.GetComponent{T}"/> should return</param>
        /// <returns>A mock <see cref="IClient"/></returns>
        protected IInstance MockInterfaceToRepo(ITGRepository repo)
        {
            var mock = new Mock <IInstance>();

            mock.Setup(foo => foo.Repository).Returns(repo);
            return(mock.Object);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the <paramref name="owner"/> and <paramref name="name"/> of a given <paramref name="repo"/>'s remote. Shows an error if the target remote isn't GitHub
        /// </summary>
        /// <param name="repo">The <see cref="ITGRepository"/> to get the remote of</param>
        /// <param name="owner">The owner of the remote <see cref="Octokit.Repository"/></param>
        /// <param name="name">The remote <see cref="Octokit.Repository.Name"/></param>
        /// <returns><see langword="true"/> if <paramref name="repo"/>'s remote was a valid GitHub <see cref="Octokit.Repository"/>, <see langword="false"/> otherwise and the user was prompted</returns>
        public static bool GetRepositoryRemote(ITGRepository repo, out string owner, out string name)
        {
            string remote = null;

            remote = repo.GetRemote(out string error);
            if (remote == null)
            {
                MessageBox.Show(String.Format("Error retrieving remote repository: {0}", error));
                owner = null;
                name  = null;
                return(false);
            }
            if (!remote.Contains("github.com"))
            {
                MessageBox.Show("Pull request support is only available for GitHub based repositories!", "Error");
                owner = null;
                name  = null;
                return(false);
            }

            //Assume standard gh format: [(git)|(https)]://github.com/owner/repo(.git)[0-1]
            var splits = remote.Split('/');

            name  = splits[splits.Length - 1];
            owner = splits[splits.Length - 2].Split('.')[0];
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a mock <see cref="IServerInterface"/> that returns a specific <see cref="ITGRepository"/> when that component is requested
        /// </summary>
        /// <param name="repo">The <see cref="ITGRepository"/> the resulting <see cref="IServerInterface.GetComponent{T}"/> should return</param>
        /// <returns>A mock <see cref="IServerInterface"/></returns>
        protected IServerInterface MockInterfaceToRepo(ITGRepository repo)
        {
            var mock = new Mock <IServerInterface>();

            mock.Setup(foo => foo.GetComponent <ITGRepository>()).Returns(repo);
            return(mock.Object);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Calls <see cref="ITGRepository.GenerateChangelog(out string)"/> and shows the user an error prompt if it fails
        /// </summary>
        /// <param name="repo">The <see cref="ITGRepository"/> to call <see cref="ITGRepository.GenerateChangelog(out string)"/> on</param>
        async void GenerateChangelog(ITGRepository repo)
        {
            string error = null;

            await WrapServerOp(() => repo.GenerateChangelog(out error));

            if (error != null)
            {
                MessageBox.Show(String.Format("Error generating changelog: {0}", error));
            }
        }
        /// <summary>
        /// Gets the <paramref name="owner"/> and <paramref name="name"/> of a given <paramref name="repo"/>'s remote. Shows an error if the target remote isn't GitHub
        /// </summary>
        /// <param name="repo">The <see cref="ITGRepository"/> to get the remote of</param>
        /// <param name="owner">The owner of the remote <see cref="Octokit.Repository"/></param>
        /// <param name="name">The remote <see cref="Octokit.Repository.Name"/></param>
        /// <returns><see langword="true"/> if <paramref name="repo"/>'s remote was a valid GitHub <see cref="Octokit.Repository"/>, <see langword="false"/> otherwise and the user was prompted</returns>
        public static bool GetRepositoryRemote(ITGRepository repo, out string owner, out string name)
        {
            string remote = null;

            remote = repo.GetRemote(out string error);
            if (remote == null)
            {
                MessageBox.Show(String.Format("Error retrieving remote repository: {0}", error));
                owner = null;
                name  = null;
                return(false);
            }
            if (!remote.Contains("github.com"))
            {
                MessageBox.Show("Pull request support is only available for GitHub based repositories!", "Error");
                owner = null;
                name  = null;
                return(false);
            }

            //Assume standard gh format: [(git)|(https)]://github.com/owner/repo(.git)[0-1]
            //Yes use .git twice in case it was weird
            var toRemove = new string[] { ".git", "/", ".git" };

            foreach (string item in toRemove)
            {
                if (remote.EndsWith(item))
                {
                    remote = remote.Substring(0, remote.LastIndexOf(item));
                }
            }
            var splits = remote.Split('/');

            name  = splits[splits.Length - 1];
            owner = splits[splits.Length - 2].Split('.')[0];
            return(true);
        }