Skip to content

Enforce Copyright Headers

Automatically require copyright headers for all new source code files.

Enforce Copyright Headers

Configuration Description

Conditions (all must be true):

  • The PR creates a new file inside the /src directory that lacks a specified copyright header at the top of the file.

Automation Actions:

  • Request changes and post a comment that explains the copyright header requirement.

Enforce Copyright Headers

# -*- mode: yaml -*-
manifest:
  version: 1.0
automations:
  enforce_copyright_header: 
    if:   
      - {{ source.diff.files | filter(attr='new_file', regex=r/src\//) | map(attr='original_file') | match(regex=r/^$/) | some }}
      - {{ source.diff.files | matchDiffLines(regex=licence.licenceRegex) | nope }}

    run:
      - action: add-comment@v1
        args: 
          comment: | 
            All new files in the '/src' directory must include the required copyright header at the top of the file. For example:
              // Copyright (c) ORG  and contributors. All rights reserved.
             // Licensed under the MIT license. See LICENSE file in the project root for details.

licence:
  licenceRegex: r/(Copyright \(c\) )|(Licensed under the MIT license)/

Additional Resources

gitStream is a workflow automation tool that enables you to use YAML configuration files to optimize your code review process. Add context to PRs, find code experts for reviews, and automate the merge process to maximize developer productivity.

Learn More about how gitStream Works.

Related Automations:

More Automations can be found on the Automation Library and Integrations pages.