Skip to content
Open
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
48 changes: 4 additions & 44 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,14 @@ name: Publish PR Preview
on:
pull_request:
types: [labeled]
workflow_dispatch:
inputs:
pr_number:
description: Pull request number to publish
required: true
type: string
publish_test_pypi:
description: Publish the Python package to TestPyPI
required: true
default: true
type: boolean
publish_docker:
description: Publish socketdev/cli:pr-<number> to Docker Hub
required: true
default: false
type: boolean
sdk_preview_version:
description: Optional exact TestPyPI socketdev prerelease for the Docker image
required: false
type: string

concurrency:
group: publish-pr-preview-${{ github.event.pull_request.number || github.run_id }}
group: publish-pr-preview-${{ github.event.pull_request.number }}
cancel-in-progress: false

jobs:
context:
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.label.name == 'publish-preview' ||
github.event.label.name == 'publish-docker-preview') &&
github.event.pull_request.head.repo.full_name == github.repository
Expand All @@ -48,28 +27,15 @@ jobs:
id: context
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
EVENT_PR_NUMBER: ${{ github.event.pull_request.number }}
INPUT_PR_NUMBER: ${{ inputs.pr_number }}
WORKFLOW_REF: ${{ github.ref }}
with:
script: |
const rawPrNumber = context.eventName === 'workflow_dispatch'
? process.env.INPUT_PR_NUMBER
: process.env.EVENT_PR_NUMBER;
const rawPrNumber = process.env.EVENT_PR_NUMBER;
if (!/^[1-9][0-9]*$/.test(rawPrNumber || '')) {
core.setFailed('Pull request number must contain ASCII digits only.');
return;
}
if (context.eventName === 'workflow_dispatch') {
const defaultRef = `refs/heads/${process.env.DEFAULT_BRANCH}`;
if (process.env.WORKFLOW_REF !== defaultRef) {
core.setFailed(`Run manual previews from ${defaultRef}.`);
return;
}
}
const prNumber = Number(rawPrNumber);
if (!Number.isSafeInteger(prNumber)) {
core.setFailed('Pull request number is outside the supported range.');
Expand Down Expand Up @@ -162,9 +128,7 @@ jobs:

publish-package:
needs: [context, build]
if: >-
github.event.label.name == 'publish-preview' ||
(github.event_name == 'workflow_dispatch' && inputs.publish_test_pypi)
if: github.event.label.name == 'publish-preview'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
Expand Down Expand Up @@ -228,9 +192,7 @@ jobs:
publish-docker:
needs: [context, build]
if: >-
github.event.label.name == 'publish-docker-preview' ||
(github.event_name == 'workflow_dispatch' && inputs.publish_docker)
if: github.event.label.name == 'publish-docker-preview'
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
Expand Down Expand Up @@ -274,8 +236,6 @@ jobs:
# arm64 layer builds under emulation, so expect roughly double the runtime.
platforms: linux/amd64,linux/arm64
tags: socketdev/cli:pr-${{ needs.context.outputs.pr_number }}
build-args: |
SDK_PREVIEW_VERSION=${{ inputs.sdk_preview_version }}

- name: Comment on pull request
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
Expand Down
16 changes: 4 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Before opening a pull request, run:

```bash
make test
uv run hatch build
uv build
uv run python -m twine check dist/*
```

Expand Down Expand Up @@ -44,19 +44,11 @@ needs testing:
`socketdev/cli:pr-<pull-request-number>` image to Docker Hub and adds or
updates a pull request comment with the image tag.

Both label-triggered and manually dispatched previews are limited to open pull
requests whose branches belong to this repository. Each label is handled as a
separate event, so applying both labels starts two workflow runs. Use manual
dispatch instead when both artifacts should be published in a single run.
Previews are limited to open pull requests whose branches belong to this
repository. Each label is handled as a separate event, so applying both labels
starts two workflow runs.

The workflow reacts when a label is added; pushing another commit while the
label remains on the pull request does not publish a new preview. To publish the
new pull request head or retry a failed publication, remove the relevant label
and apply it again.

Maintainers can also open **Actions > Publish PR Preview > Run workflow**, run
it from the repository's default branch, enter the pull request number, and
choose whether to publish to TestPyPI, Docker Hub, or both. When testing the CLI
against an SDK preview, enter the exact TestPyPI `socketdev` prerelease in
`sdk_preview_version`; publish the SDK preview first and allow time for
TestPyPI to expose it before starting the CLI Docker preview.
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ GitLab:
python -m venv .venv
source .venv/bin/activate
uv sync
uv add --dev pre-commit
uv tool install pre-commit
pre-commit install
```

Expand Down
9 changes: 1 addition & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "hatchling.build"

[project]
name = "socketsecurity"
version = "2.16.0"
version = "2.16.1"
requires-python = ">= 3.11"
license = {"file" = "LICENSE"}
dependencies = [
Expand Down Expand Up @@ -54,8 +54,6 @@ dev = [
"ruff==0.17.6",
"twine==7.0.0", # for building
"uv==0.13.10", # for dependency management
"pre-commit==4.7.0",
"hatch==1.18.2"
]

[project.scripts]
Expand Down Expand Up @@ -167,8 +165,3 @@ docstring-code-line-length = "dynamic"

[tool.hatch.build.targets.wheel]
include = ["socketsecurity", "LICENSE"]

[dependency-groups]
dev = [
"pre-commit>=4.3.0",
]
2 changes: 1 addition & 1 deletion socketsecurity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__author__ = 'socket.dev'
__version__ = '2.16.0'
__version__ = '2.16.1'
USER_AGENT_NAME = 'socket-python-cli'
USER_AGENT = f'{USER_AGENT_NAME}/{__version__}'
26 changes: 15 additions & 11 deletions socketsecurity/fossa_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,28 @@ def _build_epss(props: dict[str, Any]) -> dict[str, Any]:
}


# CVSS base metrics, as (FOSSA metric name, Socket alert prop key).
_CVSS_METRIC_FIELDS = (
("Attack Vector", "attackVector"),
("Attack Complexity", "attackComplexity"),
("Privileges Required", "privilegesRequired"),
("User Interaction", "userInteraction"),
("Scope", "scope"),
("Confidentiality Impact", "confidentialityImpact"),
("Integrity Impact", "integrityImpact"),
("Availability Impact", "availabilityImpact"),
)


def _build_metrics(props: dict[str, Any]) -> list[dict[str, Any]]:
metrics = props.get("metrics")
if isinstance(metrics, list):
return metrics

metric_map = [
("Attack Vector", props.get("attackVector")),
("Attack Complexity", props.get("attackComplexity")),
("Privileges Required", props.get("privilegesRequired")),
("User Interaction", props.get("userInteraction")),
("Scope", props.get("scope")),
("Confidentiality Impact", props.get("confidentialityImpact")),
("Integrity Impact", props.get("integrityImpact")),
("Availability Impact", props.get("availabilityImpact")),
]
metric_values = ((name, props.get(key)) for name, key in _CVSS_METRIC_FIELDS)
return [
{"name": name, "value": value}
for name, value in metric_map
for name, value in metric_values
if value not in (None, "")
]

Expand Down
Loading