Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update issueDashURL to contain correct revision branch #1433

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# FOSSA CLI Changelog

## Unreleased
## 3.9.19
- Updated the license to CPAL, an OSI-approved license similar to MPL ([#1431](https://github.com/fossas/fossa-cli/pull/1431)).
- `fossa test`: Update `issueDashURL` to contain correct branch [#1433](https://github.com/fossas/fossa-cli/pull/1433).

## v3.9.18
- Resolves an issue where `vendored-dependencies` were rescanned locally, but not in the FOSSA service,
Expand Down
30 changes: 24 additions & 6 deletions src/App/Fossa/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import App.Fossa.PreflightChecks (PreflightCommandChecks (TestChecks), preflight
import App.Fossa.Subcommand (SubCommand)
import App.Types (
ProjectRevision (projectName, projectRevision),
projectBranch,
)
import Control.Algebra (Has)
import Control.Carrier.Debug (ignoreDebug)
Expand All @@ -30,7 +31,7 @@ import Control.Effect.Lift (Lift)
import Control.Timeout (timeout')
import Data.Aeson qualified as Aeson
import Data.String.Conversion (decodeUtf8)
import Data.Text (Text)
import Data.Text (Text, replace)
import Data.Text.Extra (showT)
import Effect.Logger (
Logger,
Expand All @@ -41,7 +42,7 @@ import Effect.Logger (
pretty,
vsep,
)
import Fossa.API.Types (Issues (..))
import Fossa.API.Types (Issue, Issues (..), issueDashURL)

testSubCommand :: SubCommand TestCliOpts TestConfig
testSubCommand = Config.mkSubCommand testMain
Expand Down Expand Up @@ -84,23 +85,28 @@ testMain config = do
logSticky ""
logInfo ""

let updatedIssues =
case (projectBranch revision) of
Nothing -> issues
Just branch -> updateIssuesDashURL branch issues

case issuesCount issues of
0 -> do
logInfo . pretty $ successMsg diffRev
case outputType of
TestOutputPretty -> pure ()
TestOutputJson -> renderJson issues
TestOutputJson -> renderJson updatedIssues
n -> do
if null (issuesIssues issues)
if null (issuesIssues updatedIssues)
then
logError $
vsep
[ "A push-only API key was used, so issue details cannot be displayed."
, "Check the webapp for issue details, or rerun this command with a full-access API key."
]
else case outputType of
TestOutputPretty -> logError $ pretty issues
TestOutputJson -> renderJson issues
TestOutputPretty -> logError $ pretty updatedIssues
TestOutputJson -> renderJson updatedIssues
fatalText $ issuesFoundMsg diffRev n
where
successMsg :: Maybe DiffRevision -> Text
Expand All @@ -119,3 +125,15 @@ testMain config = do

renderJson :: (Has (Lift IO) sig m, Has Logger sig m) => Issues -> m ()
renderJson = logStdout . decodeUtf8 . Aeson.encode

-- `issueDashURL` will have the branch set to `master` for all issues. The url will contain: `/refs/branch/master`
-- Update `issueDashURL` for all issues with the current revision's branch.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a specific example of before and after? I think this is close, but just write out something like /refs/branch/differentbranch

updateIssuesDashURL :: Text -> Issues -> Issues
updateIssuesDashURL projectBranch issues = issues{issuesIssues = map (updateIssueDashURL projectBranch) (issuesIssues issues)}

updateIssueDashURL :: Text -> Issue -> Issue
updateIssueDashURL projectBranch issue = issue{issueDashURL = updatedURL}
where
oldSegment = "/master/"
newSegment = "/" <> projectBranch <> "/"
updatedURL = replace oldSegment newSegment <$> issueDashURL issue
Loading