Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
alice: shouldi: contribute: cicd: groovy functions: List functions in…
Browse files Browse the repository at this point in the history
… file
  • Loading branch information
pbhutori authored Feb 6, 2023
1 parent a5e6388 commit 15c9c24
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions entities/alice/alice/shouldi/contribute/cicd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import dffml
import dffml_operations_innersource.operations
import pathlib


IsCICDJenkinsLibrary = NewType("IsCICDJenkinsLibrary", bool)
IsCICDGitHubActionsLibrary = NewType("IsCICDGitHubActionsLibrary", bool)
CICDLibrary = NewType("CICDLibrary", dict)
GroovyFunctions = NewType("GroovyFunctions",list[str])


@dffml.op(
Expand Down Expand Up @@ -41,3 +43,44 @@ def cicd_action_library(
action_file_paths: dffml_operations_innersource.operations.ActionYAMLFileWorkflowUnixStylePath,
) -> IsCICDGitHubActionsLibrary:
return bool(action_file_paths)

@dffml.op
def groovy_functions(
repo_directory: dffml_operations_innersource.operations.RepoDirectory,
groovy_file_path: dffml_operations_innersource.operations.GroovyFileWorkflowUnixStylePath,
) -> GroovyFunctions:
from pathlib import Path
txt = Path(repo_directory,groovy_file_path).read_text().splitlines()
new_list = []
idx = 0
text = "void"
for line in txt:

# if line have the input string, get the index
# of that line and put the
# line into newly created list
if line.lstrip()[:4] == "void":
line = line.split('(',1)[0]
line = line.split('void',1)[1].strip()
new_list.insert(idx, line)
idx += 1

# closing file after reading
#file_read.close()

# if length of new list is 0 that means
# the input string doesn't
# found in the text file
if len(new_list)==0:
print("\n\"" +text+ "\" is not found in file\"" "\"!")
else:

# displaying the lines
# containing given string
lineLen = len(new_list)

print("\n**** Lines containing \"" +text+ "\" ****\n")
for i in range(lineLen):
print(end=new_list[i])
print("\n")
return new_list

1 comment on commit 15c9c24

@johnandersen777
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.