Skip to content

Commit f3e6b7a

Browse files
authored
Support Ruby GIT remote dependencies (#1406)
* basic fix * handle exclamation, tests, docs * CR changes
1 parent b73c87d commit f3e6b7a

File tree

6 files changed

+22
-15
lines changed

6 files changed

+22
-15
lines changed

Changelog.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# FOSSA CLI Changelog
22

3-
## Unreleased
4-
5-
- Reports: Increase the timeout when hitting the report generation API endpoint
3+
## v3.9.13
4+
- Support GIT dependencies in Bundler projects ([#1403](https://github.com/fossas/fossa-cli/pull/1403/files))
5+
- Reports: Increase the timeout when hitting the report generation API endpoint ([#1412](https://github.com/fossas/fossa-cli/pull/1412)).
66

77
## v3.9.12
88
- `--detect-dynamic`: Fix deb tatic parsing ([#1401](https://github.com/fossas/fossa-cli/pull/1401)).

docs/references/strategies/languages/ruby/ruby.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ parse a lockfile or run the `bundle` cli to determine dependencies.
2020
2121
The lockfile strategy attempts to parse Bundler's `Gemfile.lock` lockfile. This file is created by bundler itself after a build is completed and can be distributed in order to maintain reproducible builds. It contains the following information about a Ruby project:
2222
- The location for each dependency. These locations are each separate sections and the ones of note are `GIT`, `PATH`, and `GEM` which provide their remote in the `remote: <location>` line.
23+
- `GIT` and `GEM` type dependencies are supported. `PATH` and any others are not and will show up as `GEM` type dependencies.
2324
- Each dependencies required dependencies. These required dependencies are listed in the remote sections directly following each dependency from that remote.
2425
- All direct dependencies, listed in the `DEPENDENCIES` section.
2526
- Platforms that this ruby project is compatible with, listed in the `PLATFORMS` sections.

integration-test/Analysis/RubySpec.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ rails =
2424

2525
spec :: Spec
2626
spec = do
27-
testSuiteDepResultSummary rails BundlerProjectType (DependencyResultsSummary 210 70 293 1 Complete)
27+
testSuiteDepResultSummary rails BundlerProjectType (DependencyResultsSummary 206 70 293 1 Complete)

src/Strategy/Ruby/GemfileLock.hs

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ module Strategy.Ruby.GemfileLock (
88
Section (..),
99
) where
1010

11-
import Control.Effect.Diagnostics
11+
import Control.Effect.Diagnostics (Diagnostics, context)
1212
import Data.Char qualified as C
1313
import Data.Foldable (traverse_)
1414
import Data.Functor (void)
1515
import Data.Map.Strict (Map)
1616
import Data.Map.Strict qualified as Map
17+
import Data.Maybe (fromMaybe)
1718
import Data.Set (Set)
1819
import Data.String.Conversion (toString)
1920
import Data.Text (Text)
21+
import Data.Text qualified as Text
2022
import Data.Void (Void)
2123
import DepTypes
2224
import Effect.Grapher
@@ -89,9 +91,9 @@ toDependency pkg = foldr applyLabel start
8991
}
9092

9193
applyLabel :: GemfileLabel -> Dependency -> Dependency
92-
applyLabel (GemfileVersion ver) dep = dep{dependencyVersion = Just (CEq ver)}
94+
applyLabel (GemfileVersion ver) dep = dep{dependencyVersion = dependencyVersion dep <|> (Just . CEq) ver}
9395
applyLabel (GitRemote repo maybeRevision) dep =
94-
dep{dependencyLocations = maybe repo (\revision -> repo <> "@" <> revision) maybeRevision : dependencyLocations dep}
96+
dep{dependencyType = GitType, dependencyName = repo, dependencyVersion = (Just . CEq) =<< maybeRevision, dependencyLocations = maybe repo (\revision -> repo <> "@" <> revision) maybeRevision : dependencyLocations dep}
9597
applyLabel (OtherRemote loc) dep =
9698
dep{dependencyLocations = loc : dependencyLocations dep}
9799

@@ -257,8 +259,12 @@ dependenciesSectionParser = L.nonIndented scn $
257259
_ <- chunk "DEPENDENCIES"
258260
pure $ L.IndentMany Nothing (pure . DependencySection) findDependency
259261

262+
-- Check for the Bundler convention that uses !'s to signify if a dep is from remote.
263+
-- We already check to see if the dep is part of another remote, so we can remove it.
264+
-- https://groups.google.com/g/ruby-bundler/c/QxlNGzK3rEY
265+
-- One supporting repository example: https://github.com/percy/example-rails/tree/master
260266
findDependency :: Parser DirectDep
261267
findDependency = do
262268
dep <- findDep
263269
_ <- ignored
264-
pure $ DirectDep dep
270+
pure $ DirectDep $ fromMaybe dep $ Text.stripSuffix "!" dep

test/Ruby/GemfileLockSpec.hs

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import Text.Megaparsec
1313
dependencyOne :: Dependency
1414
dependencyOne =
1515
Dependency
16-
{ dependencyType = GemType
17-
, dependencyName = "dep-one"
18-
, dependencyVersion = Just (CEq "1.0.0")
19-
, dependencyLocations = ["temp@12345"]
16+
{ dependencyType = GitType
17+
, dependencyName = "url-for-dep-one"
18+
, dependencyVersion = Just (CEq "12345")
19+
, dependencyLocations = ["url-for-dep-one@12345"]
2020
, dependencyEnvironments = mempty
2121
, dependencyTags = Map.empty
2222
}
@@ -46,7 +46,7 @@ dependencyThree =
4646
gitSection :: Section
4747
gitSection =
4848
GitSection
49-
"temp"
49+
"url-for-dep-one"
5050
(Just "12345")
5151
(Just "branch")
5252
[ Spec

test/Ruby/testdata/gemfileLock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GIT
2-
remote: temp
2+
remote: url-for-dep-one
33
revision: 12345
44
branch: branch
55
specs:
@@ -18,7 +18,7 @@ PLATFORMS
1818
ruby
1919

2020
DEPENDENCIES
21-
dep-one (~> 0.8.13)
21+
dep-one! (~> 0.8.13)
2222
dep-two (>= 4.2.1, < 5.0.0)
2323

2424
BUNDLED WITH

0 commit comments

Comments
 (0)