diff --git a/Handler/Query.hs b/Handler/Query.hs index 077a118..4d0ddfc 100644 --- a/Handler/Query.hs +++ b/Handler/Query.hs @@ -337,6 +337,26 @@ resultTable (Entity submissionId submission) = do $(widgetFile "result-table") +data GitServer = Gogs | GitLab + deriving (Eq, Show) + +guessGitServer :: Text -> Maybe GitServer +guessGitServer bareUrl + | "git.wmi.amu.edu.pl" `isPrefixOf` bareUrl = Just Gogs + | "gitlab." `isPrefixOf` bareUrl = Just GitLab + | "git." `isPrefixOf` bareUrl = Just GitLab + | otherwise = Nothing + +getHttpLink :: Repo -> Maybe (Text, Text) +getHttpLink repo = case guessGitServer bareUrl of + Just Gogs -> Just (convertToHttpLink bareUrl, "/src/" <> branch) + Just GitLab -> Just (convertToHttpLink bareUrl, "/-/tree/" <> branch) + Nothing -> Nothing + where bareUrl = T.replace "git@" "" url + url = repoUrl repo + branch = repoBranch repo + convertToHttpLink = ("https://" <>) . (T.replace ":" "/") . (T.replace ".git" "") + submissionHeader :: FullSubmissionInfo -> Maybe Text -> WidgetFor App () submissionHeader submission mVariantName = $(widgetFile "submission-header") diff --git a/templates/submission-header.hamlet b/templates/submission-header.hamlet index 0e7609f..62e9dff 100644 --- a/templates/submission-header.hamlet +++ b/templates/submission-header.hamlet @@ -11,7 +11,11 @@
submitted
#{stamp}
original repo -
#{repoUrl $ fsiRepo submission} / branch #{repoBranch $ fsiRepo submission} +
+ $maybe (url, branchPart) <- getHttpLink (fsiRepo submission) + #{repoUrl $ fsiRepo submission} / branch #{repoBranch $ fsiRepo submission} + $nothing + #{repoUrl $ fsiRepo submission} / branch #{repoBranch $ fsiRepo submission} $if submissionIsPublic $ fsiSubmission submission
publicly available at
#{publicSubmissionRepo} / branch #{publicSubmissionBranch}