One stop page for check-function writing.

Examples

Use separate PRs for fixes and features. Function checks parsed commit types.

  commits.exists(c, c.type == "fix") && commits.exists(c, c.type == "feat")
  

Page contains draft flag and not shown. Function checks changed files and its content.

  changes.filter(c,
    c.path.endsWith(".md")
    && c.chunks.exists(ch, ch.content.contains("draft:"))
)
  

Too big file change, more than 250 added lines. Using change stats.

  changes.filter(change, change.path.endsWith(".go") && change.stats().additions > 250)
  

Commit author email.

  commits.filter(commit, !commit.author.email.endsWith("@gmail.com"))
  

Values

Top level variables accessible from CEL function.

NameMeaningType
commitsDiff commits. Allows to review commit types, author, messages and other data.Commit list
changesDiff file changes. Allows to review files content, new or deleted lines.Change list
nowCurrent timetimestamp

Types

Language types

bool, int, double, string, duration, timestamp

Containers

list, map

App types

Commit

Git commit data

  // Commit data
type Commit struct {
// Message is the commit message, contains arbitrary text.
message string
// Author is the original author of the commit.
author Signature
// Committer is the one performing the commit, might be different from Author.
committer Signature
// ParentsCount is count of the parent commits of the commit.
parentsCount int
// Commit values
type string
title string
context string
issue string
// ...
}
  

Signature

Commit author and committer data

  // Signature is used to identify who and when created a commit or tag.
type Signature struct {
// Name represents a person name. It is an arbitrary string.
name string
// Email is an email, but it cannot be assumed to be well-formed.
email string
// When is the timestamp of the signature.
when time.Time
}
  

Change

  // Change represents the necessary steps to transform one file into another.
type Change struct {
// Path is file path after change
// empty if file deleted
path string
// PrevPath is file path before change
// empty if file created
// diff from Path if file renamed
prevPath string
// Chunks returns a slice of ordered changes to transform "from" File into
// "to" File. If the file is a binary one, Chunks will be empty.
chunks []Chunk
}
  

Stat

Result of calling сhange.stats()

  type Stat struct {
additions, deletions int
}
  

Chunk

  // Chunk represents a portion of a file transformation into another.
type Chunk struct {
// Content contains the portion of the file.
type Operation
// Type contains the Operation to do with this Chunk.
content string
}

// Operation: Equal, Add, Delete
  

Operators

OperatorMeaningExample
&&, ||, !, ==, <, >, -, +, /, %, *Common logic operatorsx / 2, a <= b
?:Conditional evaluationy != 0 ? x/y : 0
[]Get child by index of keysomeList[0], someMap['keyName']

Functions

Common for most types

FunctionApplied toExample
sizestring, list, mapsize("test123"), size([1, 2, 3])
stringint, double, duration, timestampstring(123)
intstring, double, timestampint("123")
doubleint, stringdouble(123)

List and map tests

FunctionPredicate matchesExample
all(x, p)all list elements or map keys[3, 6, 9].all(n, (n % 3) == 0)
exists(x, p)any list element or map key[3, 3, 3].exists(n, n == 3)
exists_one(x, p)exactly one list element or map key[3, 6, 9].exists_one(n, n == 3)

List transformations

FunctionReturnsExample
filter(x, p)Sub-list of elements[1, 2, 3].filter(i, i % 2 > 0)
map(x, t)New list with transformed elements[1, 2, 3].map(n, n * n)
map(x, p, t)New sub-list with filtered and transformed elements[1, 2, 3].map(n, n % 2 > 0, n * n)

Strings

FunctionReturnsMeaningExample
startsWithboolHas prefix"test123".startsWith("test")
endsWithboolHas suffix"123test".endsWith("test")
containsboolHas sub-string"123test".contains("test")
matchesboolHas regexp matches"123test".matches("^d+w+$"), "123test".matches("w+")
durationdurationConvert to duration. Supported suffixes: h, m, s, ms, nsduration("10h20m30s40us50ns")
timestamptimestampConvert to time. Format RFC3339timestamp("1972-01-01T10:00:20.021-05:00")

Timestamp and duration

FunctionReturnsApplied to
getMilliseconds0-999timestamp, duration
getSeconds0-59timestamp, duration
getMinutes0-59timestamp, duration
getHours0-23timestamp, duration
getDayOfWeek0-6timestamp
getDayOfMonth0-31timestamp
getMonth0-11timestamp
getFullYear0-10000timestamp
getDayOfYear0-365timestamp
-, +timestamptimestamp +/- duration
-, +durationduration +/- duration