Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: rework schema gen #5

Merged
merged 7 commits into from
May 6, 2024
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bin/
completions/
coverage.txt
dist/
/schema/*/ignore
/schema/ignore
manpages/
scm-engine
scm-engine.exe
Expand Down
215 changes: 103 additions & 112 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,7 @@
- [`label.skip_if` (optional)](#labelskip_if-optional)
- [Expr-lang information](#expr-lang-information)
- [Attributes](#attributes)
- [project](#project)
- [project.labels](#projectlabels)
- [group](#group)
- [merge_request](#merge_request)
- [merge_request.diff_stats](#merge_requestdiff_stats)
- [merge_request.first_commit](#merge_requestfirst_commit)
- [merge_request.last_commit](#merge_requestlast_commit)
- [merge_request.labels](#merge_requestlabels)
- [Functions](#functions)
- [`merge_request.modified_files`](#merge_requestmodified_files)
- [`duration`](#duration)
- [`uniq`](#uniq)
- [`filepath_dir`](#filepath_dir)
- [`limit_path_depth_to`](#limit_path_depth_to)

## Installation

Expand Down Expand Up @@ -360,7 +347,7 @@ The `skip_if` field must be a valid [Expr-lang](https://expr-lang.org/) expressi
### Attributes

> [!NOTE]
> Missing an attribute? The `schema/gitlab/schema.graphqls` file are what is used to query GitLab, adding the missing `field` to the right `type` should make it accessible.
> Missing an attribute? The `schema/gitlab.schema.graphqls` file are what is used to query GitLab, adding the missing `field` to the right `type` should make it accessible.
> Please open an issue or Pull Request if something is missing.

> [!IMPORTANT]
Expand All @@ -370,104 +357,108 @@ The following attributes are available in `script` fields.

They can be accessed exactly as shown in this list.

#### project

> [!NOTE]
> See the [GitLab GraphQL `Project` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#project) for more details about the fields.

- `project.archived` (boolean)
- `project.created_at` (time)
- `project.description` (string)
- `project.full_path` (string)
- `project.id` (string)
- `project.last_activity_at` (time)
- `project.name_with_namespace` (string)
- `project.name` (string)
- `project.path` (string)
- `project.topics[]` (array of string)
- `project.visibility` (string)

#### project.labels

> [!NOTE]
> See the [GitLab GraphQL `Label` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#label) for more details about the fields.

- `project.labels[].color` (string)
- `project.labels[].description` (string)
- `project.labels[].id` (string)
- `project.labels[].title` (string)

#### group

> See the [GitLab GraphQL `Group` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#group) for more details about the fields.

- `group.description` (string)
- `group.id` (string)
- `group.name` (string)

#### merge_request

> See the [GitLab GraphQL `MergeRequest` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#mergerequest) for more details about the fields.

- `merge_request.approvals_left` (int)
- `merge_request.approvals_required` (int)
- `merge_request.approved` (boolean)
- `merge_request.auto_merge_enabled` (int)
- `merge_request.auto_merge_strategy` (string)
- `merge_request.conflicts` (bool)
- `merge_request.created_at` (time)
- `merge_request.description` (string)
- `merge_request.diverged_from_target_branch` (bool)
- `merge_request.draft` (boolean)
- `merge_request.id` (string)
- `merge_request.iid` (string)
- `merge_request.merge_status_enum` (string)
- `merge_request.mergeable` (boolean)
- `merge_request.merged_at` (optional, time)
- `merge_request.source_branch_exists` (boolean)
- `merge_request.source_branch_protected` (boolean)
- `merge_request.source_branch` (string)
- `merge_request.squash_on_merge` (boolean)
- `merge_request.squash` (boolean)
- `merge_request.state` (string)
- `merge_request.target_branch_exists` (string)
- `merge_request.target_branch` (string)
- `merge_request.time_between_first_and_last_commit` (duration) - SCM Engine - The `duration()` between the first and last commit in the Merge Request.
- `merge_request.time_since_first_commit` (duration) - SCM Engine - The `duration()` between `now()` and the first commit in the Merge Request.
- `merge_request.time_since_last_commit` (duration) - SCM Engine - The `duration()` between `now()` and the last commit in the Merge Request.
- `merge_request.title` (string)
- `merge_request.updated_at` (time)

#### merge_request.diff_stats

> See the [GitLab GraphQL `DiffStats` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#diffstats) for more details about the fields.

- `merge_request.diff_stats[].additions` (int)
- `merge_request.diff_stats[].deletions` (int)
- `merge_request.diff_stats[].path` (string)

#### merge_request.first_commit

> See the [GitLab GraphQL `Commit` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#commit) for more details about the fields.

- `merge_request.first_commit.author_email` (string)
- `merge_request.first_commit.committed_date` (string)

#### merge_request.last_commit

> See the [GitLab GraphQL `Commit` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#commit) for more details about the fields.

- `merge_request.last_commit.author_email` (string)
- `merge_request.last_commit.committed_date` (string)

#### merge_request.labels

> See the [GitLab GraphQL `Label` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#label) for more details about the fields.

- `merge_request.labels[].color` (string)
- `merge_request.labels[].description` (string)
- `merge_request.labels[].id` (string)
- `merge_request.labels[].title` (string)
- `group.description` (string) Description of the namespace
- `group.emails_disabled` (optional bool) Indicates if a group has email notifications disabled
- `group.emails_enabled` (optional bool) Indicates if a group has email notifications enabled
- `group.full_name` (string) Full name of the namespace
- `group.full_path` (string) Full path of the namespace
- `group.id` (string) ID of the namespace
- `group.mentions_disabled` (optional bool) Indicates if a group is disabled from getting mentioned
- `group.name` (string) Name of the namespace
- `group.path` (string) Path of the namespace
- `group.visibility` (optional string) Visibility of the namespace
- `group.web_url` (string) Web URL of the group
- `merge_request.approvals_left` (optional int) Number of approvals left
- `merge_request.approvals_required` (optional int) Number of approvals required
- `merge_request.approved` (bool) Indicates if the merge request has all the required approvals
- `merge_request.auto_merge_enabled` (bool) Indicates if auto merge is enabled for the merge request
- `merge_request.auto_merge_strategy` (optional string) Selected auto merge strategy
- `merge_request.commit_count` (optional int) Number of commits in the merge request
- `merge_request.conflicts` (bool) Indicates if the merge request has conflicts
- `merge_request.created_at` (time) Timestamp of when the merge request was created
- `merge_request.description` (optional string) Description of the merge request (Markdown rendered as HTML for caching)
- `merge_request.diff_stats[].additions` (int) Number of lines added to this file
- `merge_request.diff_stats[].deletions` (int) Number of lines deleted from this file
- `merge_request.diff_stats[].path` (string) File path, relative to repository root
- `merge_request.discussion_locked` (bool) Indicates if comments on the merge request are locked to members only
- `merge_request.diverged_from_target_branch` (bool) Indicates if the source branch is behind the target branch
- `merge_request.downvotes` (int) Number of downvotes for the merge request
- `merge_request.draft` (bool) Indicates if the merge request is a draft
- `merge_request.first_commit.author_email` (optional string) Commit author’s email
- `merge_request.first_commit.author_name` (optional string) Commit authors name
- `merge_request.first_commit.authored_date` (optional time) Timestamp of when the commit was authored
- `merge_request.first_commit.committed_date` (optional time) Timestamp of when the commit was committed
- `merge_request.first_commit.committer_email` (optional string) Email of the committer
- `merge_request.first_commit.committer_name` (optional string) Name of the committer
- `merge_request.first_commit.description` (optional string) Description of the commit message
- `merge_request.first_commit.full_title` (optional string) Full title of the commit message
- `merge_request.first_commit.id` (optional string) ID (global ID) of the commit
- `merge_request.first_commit.message` (optional string) Raw commit message
- `merge_request.first_commit.sha` (string) SHA1 ID of the commit
- `merge_request.first_commit.short_id` (string) Short SHA1 ID of the commit
- `merge_request.first_commit.title` (optional string) Title of the commit message
- `merge_request.first_commit.web_url` (string) Web URL of the commit
- `merge_request.force_remove_source_branch` (optional bool) Indicates if the project settings will lead to source branch deletion after merge
- `merge_request.id` (string) ID of the merge request
- `merge_request.iid` (string) Internal ID of the merge request
- `merge_request.labels[].color` (string) Background color of the label
- `merge_request.labels[].description` (string) Description of the label (Markdown rendered as HTML for caching)
- `merge_request.labels[].id` (string) Label ID
- `merge_request.labels[].title` (string) Content of the label
- `merge_request.last_commit.author_email` (optional string) Commit author’s email
- `merge_request.last_commit.author_name` (optional string) Commit authors name
- `merge_request.last_commit.authored_date` (optional time) Timestamp of when the commit was authored
- `merge_request.last_commit.committed_date` (optional time) Timestamp of when the commit was committed
- `merge_request.last_commit.committer_email` (optional string) Email of the committer
- `merge_request.last_commit.committer_name` (optional string) Name of the committer
- `merge_request.last_commit.description` (optional string) Description of the commit message
- `merge_request.last_commit.full_title` (optional string) Full title of the commit message
- `merge_request.last_commit.id` (optional string) ID (global ID) of the commit
- `merge_request.last_commit.message` (optional string) Raw commit message
- `merge_request.last_commit.sha` (string) SHA1 ID of the commit
- `merge_request.last_commit.short_id` (string) Short SHA1 ID of the commit
- `merge_request.last_commit.title` (optional string) Title of the commit message
- `merge_request.last_commit.web_url` (string) Web URL of the commit
- `merge_request.merge_status_enum` (string) Merge status of the merge request
- `merge_request.merge_when_pipeline_succeeds` (optional bool) Indicates if the merge has been set to auto-merge
- `merge_request.mergeable` (bool) Indicates if the merge request is mergeable
- `merge_request.mergeable_discussions_state` (optional bool) Indicates if all discussions in the merge request have been resolved, allowing the merge request to be merged
- `merge_request.merged_at` (optional time) Timestamp of when the merge request was merged, null if not merged
- `merge_request.prepared_at` (optional time) Timestamp of when the merge request was prepared
- `merge_request.should_be_rebased` (bool) Indicates if the merge request will be rebased
- `merge_request.should_remove_source_branch` (optional bool) Indicates if the source branch of the merge request will be deleted after merge
- `merge_request.source_branch` (string) Source branch of the merge request
- `merge_request.source_branch_exists` (bool) Indicates if the source branch of the merge request exists
- `merge_request.source_branch_protected` (bool) Indicates if the source branch is protected
- `merge_request.squash` (bool) Indicates if the merge request is set to be squashed when merged. Project settings may override this value. Use squash_on_merge instead to take project squash options into account
- `merge_request.squash_on_merge` (bool) Indicates if the merge request will be squashed when merged
- `merge_request.state` (string) State of the merge request
- `merge_request.target_branch` (string) Target branch of the merge request
- `merge_request.target_branch_exists` (bool) Indicates if the target branch of the merge request exists
- `merge_request.time_between_first_and_last_commit` (optional duration)
- `merge_request.time_since_first_commit` (optional duration)
- `merge_request.time_since_last_commit` (optional duration)
- `merge_request.title` (string) Title of the merge request
- `merge_request.updated_at` (time) Timestamp of when the merge request was last updated
- `merge_request.upvotes` (int) Number of upvotes for the merge request.
- `merge_request.user_discussions_count` (optional int) Number of user discussions in the merge request
- `merge_request.user_notes_count` (optional int) User notes count of the merge request
- `project.archived` (bool) Indicates the archived status of the project
- `project.created_at` (time) Timestamp of the project creation
- `project.description` (string) Short description of the project
- `project.full_path` (string) Full path of the project
- `project.id` (string) ID of the project
- `project.issues_enabled` (bool) Indicates if Issues are enabled for the current user
- `project.labels[].color` (string) Background color of the label
- `project.labels[].description` (string) Description of the label (Markdown rendered as HTML for caching)
- `project.labels[].id` (string) Label ID
- `project.labels[].title` (string) Content of the label
- `project.last_activity_at` (time) Timestamp of the project last activity
- `project.name` (string) Name of the project (without namespace)
- `project.name_with_namespace` (string) Full name of the project with its namespace
- `project.path` (string) Path of the project
- `project.topics` ([]string) List of project topics
- `project.visibility` (string) Visibility of the project

### Functions

Expand Down
6 changes: 3 additions & 3 deletions pkg/scm/gitlab/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewContext(ctx context.Context, baseURL, token string) (*Context, error) {
if len(evalContext.MergeRequest.ResponseFirstCommits.Nodes) > 0 {
evalContext.MergeRequest.FirstCommit = &evalContext.MergeRequest.ResponseFirstCommits.Nodes[0]

tmp := time.Since(evalContext.MergeRequest.FirstCommit.CommittedDate)
tmp := time.Since(*evalContext.MergeRequest.FirstCommit.CommittedDate)
evalContext.MergeRequest.TimeSinceFirstCommit = &tmp
}

Expand All @@ -66,14 +66,14 @@ func NewContext(ctx context.Context, baseURL, token string) (*Context, error) {
if len(evalContext.MergeRequest.ResponseLastCommits.Nodes) > 0 {
evalContext.MergeRequest.LastCommit = &evalContext.MergeRequest.ResponseLastCommits.Nodes[0]

tmp := time.Since(evalContext.MergeRequest.LastCommit.CommittedDate)
tmp := time.Since(*evalContext.MergeRequest.LastCommit.CommittedDate)
evalContext.MergeRequest.TimeSinceLastCommit = &tmp
}

evalContext.MergeRequest.ResponseLastCommits = nil

if evalContext.MergeRequest.FirstCommit != nil && evalContext.MergeRequest.LastCommit != nil {
tmp := evalContext.MergeRequest.FirstCommit.CommittedDate.Sub(evalContext.MergeRequest.LastCommit.CommittedDate).Round(time.Hour)
tmp := evalContext.MergeRequest.FirstCommit.CommittedDate.Sub(*evalContext.MergeRequest.LastCommit.CommittedDate).Round(time.Hour)
evalContext.MergeRequest.TimeBetweenFirstAndLastCommit = &tmp
}

Expand Down
9 changes: 9 additions & 0 deletions schema/docs.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- define "attributes" -}}
{{- range .Attributes -}}
{{ if .IsCustomType -}}{{- template "attributes" . }}{{- else }}
- `{{ .BlockName }}` ({{ if .Optional }}optional {{ end }}{{ .Type }}) {{ .Description }}{{- end -}}
{{- end }}
{{- end -}}

### Attributes
{{ template "attributes" . -}}
3 changes: 3 additions & 0 deletions schema/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package schema

//go:generate go run gitlab.go
Loading
Loading