Skip to content

Output to YAML #41

Description

@samrocketman

It would be cool if this outputs to YAML. Do you accept pull requests?

Here's a fast proof of concept I use with awk.

Example output

The following example assumes I have ~/usr/bin in my $PATH.

$ curl -sSfL https://github.com/hmarr/codeowners/releases/download/v1.2.1/codeowners_1.2.1_darwin_arm64.tar.gz | tar -xz -C ~/usr/bin/ codeowners

$ cat > ~/usr/bin/codeowners-to-yaml.awk <<'EOF'
#!/usr/bin/awk -f
BEGIN {
    print "codeowners:";
};
{
    print "  - file: \""$1"\"\n    reviewers:";
    for(i=2; i<=NF; i++) {
        print "      - \""$i"\"";
    }
}
EOF

$ chmod 755 ~/usr/bin/codeowners-to-yaml.awk

$ git diff --diff-filter=AM --name-only "$(git merge-base origin/main HEAD)" HEAD | xargs codeowners | codeowners-to-yaml.awk
codeowners:
  - file: "some-file"
    reviewers:
      - "@org/team1"
      - "@org/team2"
  - file: "another-file"
    reviewers:
      - "@org/team3"

The YAML produced by the above PoC from codeowners output.

codeowners:
  - file: "some-file"
    reviewers:
      - "@org/team1"
      - "@org/team2"
  - file: "another-file"
    reviewers:
      - "@org/team3"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions