Class GitLabUtils


  • public class GitLabUtils
    extends Object

    Utility methods for the gitlab repository.

    Author:
    rmartinc
    • Constructor Summary

      Constructors 
      Constructor Description
      GitLabUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkIsInRepo​(URL url, URL repoUrl)
      If the url is not in the repoURL a NotFoundException is thrown.
      static String[] getProjectIdAndLastFieldFromURL​(URL url)
      Return the projectId and the last path part in a two sized array.
      static String getProjectIdFromURL​(URL url)
      Return the project id from a gitlab repo URL.
      static org.jboss.set.aphrodite.domain.CommitStatus toCommitStatus​(String statusValue)
      Converts a gitlan commit status into an aphrodite commit status.
      static org.jboss.set.aphrodite.domain.Label toLabel​(org.gitlab4j.api.models.Label l, URL repoUrl)
      Converts a gitlab label into an aphrodite one.
      static boolean toMergeable​(String mergeStatus)
      Returns if the merge status is a mergeable aphrodite status.
      static org.jboss.set.aphrodite.domain.PullRequest toPullRequest​(org.gitlab4j.api.models.MergeRequest m, List<org.gitlab4j.api.models.Commit> commits, URL url, org.jboss.set.aphrodite.domain.Repository repo, org.jboss.set.aphrodite.domain.spi.PullRequestHome prHome)
      Converts a gitlab merge object into an aphrodite pull request.
      static org.jboss.set.aphrodite.domain.PullRequestState toPullRequestState​(String state)
      Converts gitlab state into a PullRequestState
      static boolean urlIsInRepo​(URL url, URL repoUrl)
      Method to check if an URL is in the repo URL.
    • Constructor Detail

      • GitLabUtils

        public GitLabUtils()
    • Method Detail

      • getProjectIdFromURL

        public static String getProjectIdFromURL​(URL url)
        Return the project id from a gitlab repo URL. The URL is in the form: http(s)://hostname:port/group/project and the method returns the part group/project.
        Parameters:
        url - The gitab repo URL
        Returns:
        The project id in the form group/project
      • getProjectIdAndLastFieldFromURL

        public static String[] getProjectIdAndLastFieldFromURL​(URL url)
        Return the projectId and the last path part in a two sized array. The first string will be the project ID and the second the last path. For the URL http(s)://hostname:port/group/project/.../32 the method returns the array ["group/project", "32"].
        Parameters:
        url - The URL to parse
        Returns:
        The array with two parts or null
      • urlIsInRepo

        public static boolean urlIsInRepo​(URL url,
                                          URL repoUrl)
        Method to check if an URL is in the repo URL. The method checks the protocol, hostname and port of both URLS.
        Parameters:
        url - The URL to check
        repoUrl - The repository URL
        Returns:
        true if the URL is in the same origin than the repo URL
      • checkIsInRepo

        public static void checkIsInRepo​(URL url,
                                         URL repoUrl)
                                  throws org.jboss.set.aphrodite.spi.NotFoundException
        If the url is not in the repoURL a NotFoundException is thrown.
        Parameters:
        url - The URL to check
        repoUrl - The repository URL
        Throws:
        org.jboss.set.aphrodite.spi.NotFoundException - If url is not in repoUrl
      • toPullRequestState

        public static org.jboss.set.aphrodite.domain.PullRequestState toPullRequestState​(String state)
        Converts gitlab state into a PullRequestState
        Parameters:
        state - The gitlab state
        Returns:
        The aphrodite state
      • toMergeable

        public static boolean toMergeable​(String mergeStatus)
        Returns if the merge status is a mergeable aphrodite status.
        Parameters:
        mergeStatus - The gitlab merge status
        Returns:
        true is it's mergeable
      • toCommitStatus

        public static org.jboss.set.aphrodite.domain.CommitStatus toCommitStatus​(String statusValue)
        Converts a gitlan commit status into an aphrodite commit status.
        Parameters:
        statusValue - The gitlab status of the commit
        Returns:
        The equivalent status in aphrodite
      • toPullRequest

        public static org.jboss.set.aphrodite.domain.PullRequest toPullRequest​(org.gitlab4j.api.models.MergeRequest m,
                                                                               List<org.gitlab4j.api.models.Commit> commits,
                                                                               URL url,
                                                                               org.jboss.set.aphrodite.domain.Repository repo,
                                                                               org.jboss.set.aphrodite.domain.spi.PullRequestHome prHome)
        Converts a gitlab merge object into an aphrodite pull request.
        Parameters:
        m - The gilab merge object
        commits - The commits of the merge request
        url - The URL for the merge
        repo - The repository of the merge
        prHome - The pull request home to use in the or
        Returns:
        The aphrodite PullRequesy
      • toLabel

        public static org.jboss.set.aphrodite.domain.Label toLabel​(org.gitlab4j.api.models.Label l,
                                                                   URL repoUrl)
        Converts a gitlab label into an aphrodite one.
        Parameters:
        l - The gitlab label
        repoUrl - The label URL
        Returns:
        The aphrodite label