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
14 changes: 12 additions & 2 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ on:
type: string

concurrency:
group: publish-pr-preview-${{ github.event.pull_request.number || github.run_id }}
group: publish-pr-preview-${{ github.event.pull_request.number || inputs.pr_number || github.run_id }}
cancel-in-progress: false
queue: max
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

jobs:
context:
Expand All @@ -43,6 +44,7 @@ jobs:
outputs:
pr_number: ${{ steps.context.outputs.pr_number }}
head_sha: ${{ steps.context.outputs.head_sha }}
sdk_preview_version: ${{ steps.context.outputs.sdk_preview_version }}
steps:
- name: Validate pull request context
id: context
Expand All @@ -51,6 +53,7 @@ jobs:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
EVENT_PR_NUMBER: ${{ github.event.pull_request.number }}
INPUT_PR_NUMBER: ${{ inputs.pr_number }}
INPUT_SDK_PREVIEW_VERSION: ${{ inputs.sdk_preview_version }}
WORKFLOW_REF: ${{ github.ref }}
with:
script: |
Expand All @@ -62,12 +65,18 @@ jobs:
return;
}

let sdkPreviewVersion = '';
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;
}
sdkPreviewVersion = process.env.INPUT_SDK_PREVIEW_VERSION || '';
if (/[^0-9a-zA-Z.!+_-]/.test(sdkPreviewVersion)) {
core.setFailed('SDK preview version must be a single package version.');
return;
}
}

const prNumber = Number(rawPrNumber);
Expand All @@ -91,6 +100,7 @@ jobs:

core.setOutput('pr_number', String(prNumber));
core.setOutput('head_sha', pullRequest.head.sha);
core.setOutput('sdk_preview_version', sdkPreviewVersion);

build:
needs: context
Expand Down Expand Up @@ -275,7 +285,7 @@ jobs:
platforms: linux/amd64,linux/arm64
tags: socketdev/cli:pr-${{ needs.context.outputs.pr_number }}
build-args: |
SDK_PREVIEW_VERSION=${{ inputs.sdk_preview_version }}
SDK_PREVIEW_VERSION=${{ needs.context.outputs.sdk_preview_version }}

- name: Comment on pull request
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
Expand Down
11 changes: 7 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ dependencies:
uv sync --all-extras
```

To install or migrate the version-sync Git hook, see the
[development guide](docs/development.md#version-sync-hook).

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 @@ -45,9 +48,9 @@ needs testing:
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.
requests whose branches belong to this repository. Each label starts a separate
run. Preview runs for the same pull request wait in a queue so both labels can
publish when a preview is already running.

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
Expand Down
13 changes: 11 additions & 2 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,17 @@ GitLab:
python -m venv .venv
source .venv/bin/activate
uv sync
uv add --dev pre-commit
pre-commit install
```

## Version-sync hook

Install `pre-commit` outside the project's virtual environment. If your existing
hook was installed from `.venv`, reinstall it with the commands below so it
continues to work after `uv sync` removes the project copy of `pre-commit`.

```bash
uv tool install pre-commit
"$(uv tool dir --bin)/pre-commit" install
```

## Related docs
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
24 changes: 24 additions & 0 deletions tests/unit/test_fossa_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,30 @@ def test_fossa_report_payload_vulnerability_shape_is_stable():
assert generated_vulnerability["source"]["packageManager"] == "pip"
assert generated_vulnerability["vulnId"] == "GHSA-9hjg-9r4m-mvj7"
assert generated_vulnerability["cve"] == "CVE-2024-47081"
expected_metrics = [
{"name": "Attack Vector", "value": "Network"},
{"name": "Attack Complexity", "value": "High"},
{"name": "Privileges Required", "value": "None"},
{"name": "User Interaction", "value": "Required"},
{"name": "Scope", "value": "Unchanged"},
{"name": "Confidentiality Impact", "value": "High"},
{"name": "Integrity Impact", "value": "None"},
{"name": "Availability Impact", "value": "None"},
]
assert generated_vulnerability["metrics"] == expected_metrics

diff.new_alerts[0].props["attackComplexity"] = ""
del diff.new_alerts[0].props["availabilityImpact"]
assert build_fossa_report_payload(diff, config)["vulnerability"][0]["metrics"] == [
metric
for metric in expected_metrics
if metric["name"] not in {"Attack Complexity", "Availability Impact"}
]

diff.new_alerts[0].props["metrics"] = [{"name": "Attack Vector", "value": "Local"}]
assert build_fossa_report_payload(diff, config)["vulnerability"][0]["metrics"] == [
{"name": "Attack Vector", "value": "Local"},
]


def test_project_metadata_uses_dollar_revision_separator():
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_pr_preview_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import re
from pathlib import Path

WORKFLOW = Path(__file__).resolve().parents[2] / ".github/workflows/pr-preview.yml"


def test_pr_preview_queue_keeps_multiple_pending_runs():
workflow = WORKFLOW.read_text(encoding="utf-8")
concurrency = re.search(r"^concurrency:\n((?:^ .+\n)+)", workflow, re.MULTILINE)

assert concurrency is not None
assert " queue: max" in concurrency[1].splitlines()
Loading