Skip to content

Commit de2b480

Browse files
authored
Doug/add private flag for repo (#80)
* Updated config params for support private/public repo setting * Added repo visibility to shared config
1 parent 4693beb commit de2b480

File tree

6 files changed

+40
-18
lines changed

6 files changed

+40
-18
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.0.54"
9+
version = "2.0.55"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.0.54'
2+
__version__ = '2.0.55'

socketsecurity/config.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class CliConfig:
5050
timeout: Optional[int] = 1200
5151
exclude_license_details: bool = False
5252
include_module_folders: bool = False
53+
repo_is_public: bool = False
5354
version: str = __version__
5455
jira_plugin: PluginConfig = field(default_factory=PluginConfig)
5556
slack_plugin: PluginConfig = field(default_factory=PluginConfig)
@@ -94,6 +95,7 @@ def from_args(cls, args_list: Optional[List[str]] = None) -> 'CliConfig':
9495
'timeout': args.timeout,
9596
'exclude_license_details': args.exclude_license_details,
9697
'include_module_folders': args.include_module_folders,
98+
'repo_is_public': args.repo_is_public,
9799
'version': __version__
98100
}
99101
config_args.update({
@@ -147,30 +149,32 @@ def create_argument_parser() -> argparse.ArgumentParser:
147149
required=False
148150
)
149151
repo_group.add_argument(
152+
"--repo-is-public",
153+
dest="repo_is_public",
154+
action="store_true",
155+
help="If set it will flag a new repository creation as public. Defaults to false."
156+
)
157+
repo_group.add_argument(
158+
"--branch",
159+
metavar="<name>",
160+
help="Branch name",
161+
default=""
162+
)
163+
164+
integration_group = parser.add_argument_group('Integration')
165+
integration_group.add_argument(
150166
"--integration",
151167
choices=INTEGRATION_TYPES,
152168
metavar="<type>",
153-
help="Integration type",
169+
help="Integration type of api, github, gitlab, azure, or bitbucket. Defaults to api",
154170
default="api"
155171
)
156-
repo_group.add_argument(
172+
integration_group.add_argument(
157173
"--owner",
158174
metavar="<name>",
159175
help="Name of the integration owner, defaults to the socket organization slug",
160176
required=False
161177
)
162-
repo_group.add_argument(
163-
"--branch",
164-
metavar="<name>",
165-
help="Branch name",
166-
default=""
167-
)
168-
repo_group.add_argument(
169-
"--committers",
170-
metavar="<name>",
171-
help="Committer(s) to filter by",
172-
nargs="*"
173-
)
174178

175179
# Pull Request and Commit info
176180
pr_group = parser.add_argument_group('Pull Request and Commit')
@@ -209,6 +213,12 @@ def create_argument_parser() -> argparse.ArgumentParser:
209213
dest="commit_sha",
210214
help=argparse.SUPPRESS
211215
)
216+
pr_group.add_argument(
217+
"--committers",
218+
metavar="<name>",
219+
help="Committer for the commit (comma separated)",
220+
nargs="*"
221+
)
212222

213223
# Path and File options
214224
path_group = parser.add_argument_group('Path and File')

socketsecurity/core/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,12 @@ def get_repo_info(self, repo_slug: str, default_branch: str = "socket-default-br
439439
log.warning(f"Failed to get repository {repo_slug}, attempting to create it")
440440
try:
441441

442-
create_response = self.sdk.repos.post(self.config.org_slug, name=repo_slug, default_branch=default_branch)
442+
create_response = self.sdk.repos.post(
443+
self.config.org_slug,
444+
name=repo_slug,
445+
default_branch=default_branch,
446+
visibility=self.config.repo_visibility
447+
)
443448

444449
# Check if the response is empty (failure) or has content (success)
445450
if not create_response:

socketsecurity/core/socket_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class SocketConfig:
2626
full_scan_path: Optional[str] = None
2727
repository_path: Optional[str] = None
2828
security_policy: Dict = None
29+
repo_visibility: Optional[str] = 'private'
2930
all_issues: Optional['AllIssues'] = None
3031
excluded_dirs: Set[str] = field(default_factory=lambda: default_exclude_dirs)
3132
version: str = __version__

socketsecurity/socketcli.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,14 @@ def main_code():
148148
log.debug("Found manifest files or forced scan, proceeding")
149149

150150
org_slug = core.config.org_slug
151+
if config.repo_is_public:
152+
core.config.repo_visibility = "public"
151153
integration_type = config.integration_type
152154
integration_org_slug = config.integration_org_slug or org_slug
155+
try:
156+
pr_number = int(config.pr_number)
157+
except (ValueError, TypeError):
158+
pr_number = 0
153159

154160
params = FullScanParams(
155161
org_slug=org_slug,
@@ -159,7 +165,7 @@ def main_code():
159165
branch=config.branch,
160166
commit_message=config.commit_message,
161167
commit_hash=config.commit_sha,
162-
pull_request=config.pr_number,
168+
pull_request=pr_number,
163169
committers=config.committers,
164170
make_default_branch=config.default_branch,
165171
set_as_pending_head=True

0 commit comments

Comments
 (0)