Skip to content

Commit

Permalink
Tag framework routes (#95)
Browse files Browse the repository at this point in the history
* Tag rails routes

Signed-off-by: Prabhu Subramanian <[email protected]>

* Tag sinatra routes

Signed-off-by: Prabhu Subramanian <[email protected]>

---------

Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu authored Jan 8, 2025
1 parent 1037e42 commit 13e56bc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
run: |
python3.12 -m pip install --upgrade pip
python3.12 -m pip install poetry
python3.12 -m poetry self add poetry-plugin-export
python3.12 -m poetry export -f requirements.txt --with=science --without-hashes --output target/chen-science-requirements.txt
python3.12 -m poetry export -f requirements.txt --with=database --without-hashes --output target/chen-database-requirements.txt
- name: Upload chen to ghcr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,50 @@ class ChennaiTagsPass(atom: Cpg) extends CpgPass(atom):
).store()(dstGraph)
}
end tagPhpRoutes
private def tagRubyRoutes(dstGraph: DiffGraphBuilder): Unit =
// rails
val railsRoutePrefix = ".*(get|post|put|delete|head|option|resources|namespace)\\s('|\").*"
atom.method.where(
_.filename("config/routes.rb").code(
railsRoutePrefix
)
).newTagNode(
FRAMEWORK_ROUTE
).store()(dstGraph)
atom.method.where(
_.filename("config/routes.rb").code(
railsRoutePrefix
)
).parameter.newTagNode(FRAMEWORK_INPUT).store()(
dstGraph
)
atom.method.filename(".*controller.rb.*").parameter.newTagNode(FRAMEWORK_INPUT).store()(
dstGraph
)
atom.method.filename(".*controller.rb.*").methodReturn.newTagNode(
FRAMEWORK_OUTPUT
).store()(dstGraph)
// sinatra
val sinatraRoutePrefix =
"(app\\.namespace|app\\.)?(get|post|delete|head|options|put)\\s('|\").*"
atom.method.code(sinatraRoutePrefix).newTagNode(
FRAMEWORK_ROUTE
).store()(dstGraph)
atom.method.code(sinatraRoutePrefix).parameter
.newTagNode(FRAMEWORK_INPUT).store()(
dstGraph
)
atom.method.code(sinatraRoutePrefix).methodReturn.newTagNode(
FRAMEWORK_OUTPUT
).store()(dstGraph)
end tagRubyRoutes
override def run(dstGraph: DiffGraphBuilder): Unit =
if language == Languages.PYTHON || language == Languages.PYTHONSRC then
tagPythonRoutes(dstGraph)
if language == Languages.NEWC || language == Languages.C then
tagCRoutes(dstGraph)
if language == Languages.PHP then tagPhpRoutes(dstGraph)
if language == Languages.RUBYSRC then tagRubyRoutes(dstGraph)
atom.configFile("chennai.json").content.foreach { cdxData =>
val ctagsJson = parse(cdxData).getOrElse(Json.Null)
val cursor: HCursor = ctagsJson.hcursor
Expand Down

0 comments on commit 13e56bc

Please sign in to comment.