Skip to content
Merged
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
17 changes: 17 additions & 0 deletions .apache-magpie-overrides/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

user.md
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

/.idea/
/.vscode/
*.iml
Expand Down
32 changes: 17 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,28 @@ repos:
args:
- "--maxlevel"
- "3"
# Stamp an SPDX Apache-2.0 licence identifier into Markdown files so the
# Apache RAT licence check (.github/workflows/rat.yml) sees an approved
# header on every scanned file. Markdown carries no comment header by
# convention, so RAT would otherwise flag it as unapproved. Plain
# Markdown gets an HTML-comment header on line 1; files with YAML front
# matter get a `# SPDX-License-Identifier` comment as the first line
# *inside* the front matter, so line 1 stays `---` and no new key is
# introduced for a front-matter validator to reject. The hook fixes files
# in place and fails the commit when it changes one (the end-of-file-fixer
# convention), so the contributor re-stages the now-stamped file. The
# `exclude` mirrors `.rat-excludes`: the third-party-licence detection
# fixtures deliberately contain non-Apache licence text and must not be
# stamped Apache-2.0.
# Stamp an approved Apache-2.0 licence header into Markdown and .gitignore
# files so the Apache RAT licence check (.github/workflows/rat.yml) — and
# any reviewer — sees an approved header on every one. Markdown and
# .gitignore carry no comment header by convention, so RAT would otherwise
# flag (or silently skip) them. Plain Markdown gets an HTML-comment header
# on line 1; files with YAML front matter get a `# SPDX-License-Identifier`
# comment as the first line *inside* the front matter, so line 1 stays
# `---` and no new key is introduced for a front-matter validator to
# reject; .gitignore gets the full ASF header as `#` comments (the block
# .gitattributes carries), matching the convention that hash-comment
# config files carry the full header. The hook fixes files in place and
# fails the commit when it changes one (the end-of-file-fixer convention),
# so the contributor re-stages the now-stamped file. The `exclude` mirrors
# `.rat-excludes`: the third-party-licence detection fixtures deliberately
# contain non-Apache licence text and must not be stamped Apache-2.0.
- repo: local
hooks:
- id: add-license-headers
name: Stamp SPDX licence header into Markdown
name: Stamp Apache licence header into Markdown and .gitignore
language: system
entry: tools/dev/add-license-headers.py
files: \.md$
files: (\.md|(^|/)\.gitignore)$
exclude: ^tools/skill-evals/evals/pr-management-code-review/step-4-third-party-license/fixtures/.*$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
Expand Down
17 changes: 17 additions & 0 deletions projects/_template/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Reassessment / reproducer campaign evidence packages are
# local-only working material: description.md and issue.json are
# verbatim, unredacted copies of the reporter's issue body and every
Expand Down
17 changes: 17 additions & 0 deletions tools/cve-tool-vulnogram/generate-cve-json/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

__pycache__/
*.py[cod]
.venv/
Expand Down
17 changes: 17 additions & 0 deletions tools/cve-tool-vulnogram/oauth-api/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

__pycache__/
.mypy_cache/
.ruff_cache/
Expand Down
85 changes: 67 additions & 18 deletions tools/dev/add-license-headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,29 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Insert an SPDX Apache-2.0 licence header into Markdown files.
"""Insert an Apache-2.0 licence header into Markdown and `.gitignore` files.

Apache RAT (see `.github/workflows/rat.yml`) requires every scanned file
to carry an approved licence header. Markdown carries no comment header by
convention, so this script stamps an SPDX identifier and the licence URL
that RAT recognises as an approved licence.
that RAT recognises as an approved licence. `.gitignore` files are
hash-comment config, so they get the full ASF header (the same block
`.gitattributes` and `.pre-commit-config.yaml` carry) — matching the
project convention that source/config files carry the full header while
Markdown carries the SPDX identifier.

Two placements, chosen per file so the stamp never breaks downstream
Placements, chosen per file so the stamp never breaks downstream
parsers:

* **`.gitignore`** — the full ASF licence header as `#` comment lines,
prepended before the ignore patterns (a leading comment block is inert
to git's ignore parser)::

# Licensed to the Apache Software Foundation (ASF) under one
# ... (full ASF header) ...
# under the License.


* **Plain Markdown** — a two-line HTML comment on the first line::

<!-- SPDX-License-Identifier: Apache-2.0
Expand All @@ -41,19 +54,20 @@
name: ...

The operation is idempotent: a file that already carries any
``SPDX-License-Identifier:`` declaration in its leading lines is left
untouched, so a hand-written header in a different comment style is never
double-stamped.
``SPDX-License-Identifier:`` declaration — or the full ASF header's first
line — in its leading lines is left untouched, so a hand-written header in
a different comment style is never double-stamped.

Usage::

# Stamp specific files (the pre-commit / prek entry point; prek passes
# the staged Markdown files as arguments). Exits non-zero if any file
# was modified, so the commit fails and the contributor re-stages the
# now-stamped file — the same convention as end-of-file-fixer.
# the staged Markdown / .gitignore files as arguments). Exits non-zero
# if any file was modified, so the commit fails and the contributor
# re-stages the now-stamped file — the same convention as
# end-of-file-fixer.
tools/dev/add-license-headers.py path/to/file.md ...

# Stamp every tracked Markdown file in the repository.
# Stamp every tracked Markdown and .gitignore file in the repository.
tools/dev/add-license-headers.py --all
"""

Expand All @@ -73,6 +87,27 @@
# the opening `---` so line 1 stays `---` and no key is introduced.
SPDX_YAML = f"# SPDX-License-Identifier: Apache-2.0\n# {_LICENSE_URL}"

# Full ASF licence header as `#` comments, for hash-comment config files
# that carry no SPDX convention (`.gitignore`) — the same block
# `.gitattributes` and `.pre-commit-config.yaml` carry.
ASF_HEADER_HASH = """\
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License."""

# How many leading lines to scan for an existing SPDX declaration.
_SCAN_LINES = 12

Expand All @@ -97,11 +132,14 @@ def _already_stamped(lines: list[str]) -> bool:
multi-line HTML comment) is left untouched rather than double-stamped.
A bare mention of the token without a ``:`` value (prose describing
SPDX) is not treated as a declaration, so such a file still gets a real
header.
header. The full ASF header (`.gitignore`) carries no SPDX token, so its
first line is recognised too.
"""
for line in lines[:_SCAN_LINES]:
if "SPDX-License-Identifier:" in line:
return True
if "Licensed to the Apache Software Foundation" in line:
return True
return False


Expand All @@ -112,27 +150,38 @@ def stamp(path: Path) -> bool:
if _already_stamped(lines):
return False
if not text:
# An empty Markdown file has no content to license; leave it be.
# An empty file has no content to license; leave it be.
return False
if lines[0].rstrip("\n") == "---":
if path.name == ".gitignore":
# Hash-comment config: full ASF header, then a blank line before the
# existing patterns (a leading comment block is inert to git).
new_text = ASF_HEADER_HASH + "\n\n" + text
elif lines[0].rstrip("\n") == "---":
new_text = lines[0] + SPDX_YAML + "\n" + "".join(lines[1:])
else:
new_text = SPDX_HTML + "\n\n" + text
path.write_text(new_text, encoding="utf-8")
return True


def _tracked_markdown() -> list[Path]:
out = subprocess.check_output(["git", "ls-files", "*.md"], text=True)
def _is_target(name: str) -> bool:
"""Files this script stamps: Markdown and `.gitignore`."""
return name.endswith(".md") or name == ".gitignore"


def _tracked_targets() -> list[Path]:
out = subprocess.check_output(
["git", "ls-files", "*.md", ".gitignore", "**/.gitignore"], text=True
)
return [Path(p) for p in out.splitlines()]


def main(argv: list[str]) -> int:
args = argv[1:]
if "--all" in args:
targets = _tracked_markdown()
targets = _tracked_targets()
else:
targets = [Path(a) for a in args if a.endswith(".md")]
targets = [Path(a) for a in args if _is_target(Path(a).name)]

modified: list[Path] = []
for path in targets:
Expand All @@ -144,7 +193,7 @@ def main(argv: list[str]) -> int:
modified.append(path)

for path in modified:
print(f"stamped SPDX header: {path}")
print(f"stamped licence header: {path}")
if modified:
print(f"\n{len(modified)} file(s) stamped. Re-stage them and commit again.")
return 1
Expand Down
17 changes: 17 additions & 0 deletions tools/egress-gateway/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

__pycache__/
*.py[cod]
.venv/
Expand Down
17 changes: 17 additions & 0 deletions tools/gmail/oauth-draft/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

__pycache__/
*.py[cod]
.venv/
Expand Down
17 changes: 17 additions & 0 deletions tools/privacy-llm/checker/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

__pycache__/
*.py[cod]
.venv/
Expand Down
17 changes: 17 additions & 0 deletions tools/privacy-llm/redactor/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

__pycache__/
*.py[cod]
.venv/
Expand Down