Skip to content

Commit 25887e0

Browse files
authored
build: rework schema gen (#5)
* build: refactor paths for code-gen * build: generate attribute docs automatically * build: remove dead headlines * build: remove verbose headlines * ci: fix missing import * add docs for all attributes * ci: sort attributes
1 parent 2c25dba commit 25887e0

11 files changed

+658
-342
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ bin/
99
completions/
1010
coverage.txt
1111
dist/
12-
/schema/*/ignore
12+
/schema/ignore
1313
manpages/
1414
scm-engine
1515
scm-engine.exe

README.md

+103-112
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,7 @@
3737
- [`label.skip_if` (optional)](#labelskip_if-optional)
3838
- [Expr-lang information](#expr-lang-information)
3939
- [Attributes](#attributes)
40-
- [project](#project)
41-
- [project.labels](#projectlabels)
42-
- [group](#group)
43-
- [merge_request](#merge_request)
44-
- [merge_request.diff_stats](#merge_requestdiff_stats)
45-
- [merge_request.first_commit](#merge_requestfirst_commit)
46-
- [merge_request.last_commit](#merge_requestlast_commit)
47-
- [merge_request.labels](#merge_requestlabels)
4840
- [Functions](#functions)
49-
- [`merge_request.modified_files`](#merge_requestmodified_files)
50-
- [`duration`](#duration)
51-
- [`uniq`](#uniq)
52-
- [`filepath_dir`](#filepath_dir)
53-
- [`limit_path_depth_to`](#limit_path_depth_to)
5441

5542
## Installation
5643

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

362349
> [!NOTE]
363-
> 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.
350+
> 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.
364351
> Please open an issue or Pull Request if something is missing.
365352

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

371358
They can be accessed exactly as shown in this list.
372359

373-
#### project
374-
375-
> [!NOTE]
376-
> See the [GitLab GraphQL `Project` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#project) for more details about the fields.
377-
378-
- `project.archived` (boolean)
379-
- `project.created_at` (time)
380-
- `project.description` (string)
381-
- `project.full_path` (string)
382-
- `project.id` (string)
383-
- `project.last_activity_at` (time)
384-
- `project.name_with_namespace` (string)
385-
- `project.name` (string)
386-
- `project.path` (string)
387-
- `project.topics[]` (array of string)
388-
- `project.visibility` (string)
389-
390-
#### project.labels
391-
392-
> [!NOTE]
393-
> See the [GitLab GraphQL `Label` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#label) for more details about the fields.
394-
395-
- `project.labels[].color` (string)
396-
- `project.labels[].description` (string)
397-
- `project.labels[].id` (string)
398-
- `project.labels[].title` (string)
399-
400-
#### group
401-
402-
> See the [GitLab GraphQL `Group` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#group) for more details about the fields.
403-
404-
- `group.description` (string)
405-
- `group.id` (string)
406-
- `group.name` (string)
407-
408-
#### merge_request
409-
410-
> See the [GitLab GraphQL `MergeRequest` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#mergerequest) for more details about the fields.
411-
412-
- `merge_request.approvals_left` (int)
413-
- `merge_request.approvals_required` (int)
414-
- `merge_request.approved` (boolean)
415-
- `merge_request.auto_merge_enabled` (int)
416-
- `merge_request.auto_merge_strategy` (string)
417-
- `merge_request.conflicts` (bool)
418-
- `merge_request.created_at` (time)
419-
- `merge_request.description` (string)
420-
- `merge_request.diverged_from_target_branch` (bool)
421-
- `merge_request.draft` (boolean)
422-
- `merge_request.id` (string)
423-
- `merge_request.iid` (string)
424-
- `merge_request.merge_status_enum` (string)
425-
- `merge_request.mergeable` (boolean)
426-
- `merge_request.merged_at` (optional, time)
427-
- `merge_request.source_branch_exists` (boolean)
428-
- `merge_request.source_branch_protected` (boolean)
429-
- `merge_request.source_branch` (string)
430-
- `merge_request.squash_on_merge` (boolean)
431-
- `merge_request.squash` (boolean)
432-
- `merge_request.state` (string)
433-
- `merge_request.target_branch_exists` (string)
434-
- `merge_request.target_branch` (string)
435-
- `merge_request.time_between_first_and_last_commit` (duration) - SCM Engine - The `duration()` between the first and last commit in the Merge Request.
436-
- `merge_request.time_since_first_commit` (duration) - SCM Engine - The `duration()` between `now()` and the first commit in the Merge Request.
437-
- `merge_request.time_since_last_commit` (duration) - SCM Engine - The `duration()` between `now()` and the last commit in the Merge Request.
438-
- `merge_request.title` (string)
439-
- `merge_request.updated_at` (time)
440-
441-
#### merge_request.diff_stats
442-
443-
> See the [GitLab GraphQL `DiffStats` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#diffstats) for more details about the fields.
444-
445-
- `merge_request.diff_stats[].additions` (int)
446-
- `merge_request.diff_stats[].deletions` (int)
447-
- `merge_request.diff_stats[].path` (string)
448-
449-
#### merge_request.first_commit
450-
451-
> See the [GitLab GraphQL `Commit` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#commit) for more details about the fields.
452-
453-
- `merge_request.first_commit.author_email` (string)
454-
- `merge_request.first_commit.committed_date` (string)
455-
456-
#### merge_request.last_commit
457-
458-
> See the [GitLab GraphQL `Commit` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#commit) for more details about the fields.
459-
460-
- `merge_request.last_commit.author_email` (string)
461-
- `merge_request.last_commit.committed_date` (string)
462-
463-
#### merge_request.labels
464-
465-
> See the [GitLab GraphQL `Label` GraphQL resource](https://docs.gitlab.com/ee/api/graphql/reference/#label) for more details about the fields.
466-
467-
- `merge_request.labels[].color` (string)
468-
- `merge_request.labels[].description` (string)
469-
- `merge_request.labels[].id` (string)
470-
- `merge_request.labels[].title` (string)
360+
- `group.description` (string) Description of the namespace
361+
- `group.emails_disabled` (optional bool) Indicates if a group has email notifications disabled
362+
- `group.emails_enabled` (optional bool) Indicates if a group has email notifications enabled
363+
- `group.full_name` (string) Full name of the namespace
364+
- `group.full_path` (string) Full path of the namespace
365+
- `group.id` (string) ID of the namespace
366+
- `group.mentions_disabled` (optional bool) Indicates if a group is disabled from getting mentioned
367+
- `group.name` (string) Name of the namespace
368+
- `group.path` (string) Path of the namespace
369+
- `group.visibility` (optional string) Visibility of the namespace
370+
- `group.web_url` (string) Web URL of the group
371+
- `merge_request.approvals_left` (optional int) Number of approvals left
372+
- `merge_request.approvals_required` (optional int) Number of approvals required
373+
- `merge_request.approved` (bool) Indicates if the merge request has all the required approvals
374+
- `merge_request.auto_merge_enabled` (bool) Indicates if auto merge is enabled for the merge request
375+
- `merge_request.auto_merge_strategy` (optional string) Selected auto merge strategy
376+
- `merge_request.commit_count` (optional int) Number of commits in the merge request
377+
- `merge_request.conflicts` (bool) Indicates if the merge request has conflicts
378+
- `merge_request.created_at` (time) Timestamp of when the merge request was created
379+
- `merge_request.description` (optional string) Description of the merge request (Markdown rendered as HTML for caching)
380+
- `merge_request.diff_stats[].additions` (int) Number of lines added to this file
381+
- `merge_request.diff_stats[].deletions` (int) Number of lines deleted from this file
382+
- `merge_request.diff_stats[].path` (string) File path, relative to repository root
383+
- `merge_request.discussion_locked` (bool) Indicates if comments on the merge request are locked to members only
384+
- `merge_request.diverged_from_target_branch` (bool) Indicates if the source branch is behind the target branch
385+
- `merge_request.downvotes` (int) Number of downvotes for the merge request
386+
- `merge_request.draft` (bool) Indicates if the merge request is a draft
387+
- `merge_request.first_commit.author_email` (optional string) Commit author’s email
388+
- `merge_request.first_commit.author_name` (optional string) Commit authors name
389+
- `merge_request.first_commit.authored_date` (optional time) Timestamp of when the commit was authored
390+
- `merge_request.first_commit.committed_date` (optional time) Timestamp of when the commit was committed
391+
- `merge_request.first_commit.committer_email` (optional string) Email of the committer
392+
- `merge_request.first_commit.committer_name` (optional string) Name of the committer
393+
- `merge_request.first_commit.description` (optional string) Description of the commit message
394+
- `merge_request.first_commit.full_title` (optional string) Full title of the commit message
395+
- `merge_request.first_commit.id` (optional string) ID (global ID) of the commit
396+
- `merge_request.first_commit.message` (optional string) Raw commit message
397+
- `merge_request.first_commit.sha` (string) SHA1 ID of the commit
398+
- `merge_request.first_commit.short_id` (string) Short SHA1 ID of the commit
399+
- `merge_request.first_commit.title` (optional string) Title of the commit message
400+
- `merge_request.first_commit.web_url` (string) Web URL of the commit
401+
- `merge_request.force_remove_source_branch` (optional bool) Indicates if the project settings will lead to source branch deletion after merge
402+
- `merge_request.id` (string) ID of the merge request
403+
- `merge_request.iid` (string) Internal ID of the merge request
404+
- `merge_request.labels[].color` (string) Background color of the label
405+
- `merge_request.labels[].description` (string) Description of the label (Markdown rendered as HTML for caching)
406+
- `merge_request.labels[].id` (string) Label ID
407+
- `merge_request.labels[].title` (string) Content of the label
408+
- `merge_request.last_commit.author_email` (optional string) Commit author’s email
409+
- `merge_request.last_commit.author_name` (optional string) Commit authors name
410+
- `merge_request.last_commit.authored_date` (optional time) Timestamp of when the commit was authored
411+
- `merge_request.last_commit.committed_date` (optional time) Timestamp of when the commit was committed
412+
- `merge_request.last_commit.committer_email` (optional string) Email of the committer
413+
- `merge_request.last_commit.committer_name` (optional string) Name of the committer
414+
- `merge_request.last_commit.description` (optional string) Description of the commit message
415+
- `merge_request.last_commit.full_title` (optional string) Full title of the commit message
416+
- `merge_request.last_commit.id` (optional string) ID (global ID) of the commit
417+
- `merge_request.last_commit.message` (optional string) Raw commit message
418+
- `merge_request.last_commit.sha` (string) SHA1 ID of the commit
419+
- `merge_request.last_commit.short_id` (string) Short SHA1 ID of the commit
420+
- `merge_request.last_commit.title` (optional string) Title of the commit message
421+
- `merge_request.last_commit.web_url` (string) Web URL of the commit
422+
- `merge_request.merge_status_enum` (string) Merge status of the merge request
423+
- `merge_request.merge_when_pipeline_succeeds` (optional bool) Indicates if the merge has been set to auto-merge
424+
- `merge_request.mergeable` (bool) Indicates if the merge request is mergeable
425+
- `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
426+
- `merge_request.merged_at` (optional time) Timestamp of when the merge request was merged, null if not merged
427+
- `merge_request.prepared_at` (optional time) Timestamp of when the merge request was prepared
428+
- `merge_request.should_be_rebased` (bool) Indicates if the merge request will be rebased
429+
- `merge_request.should_remove_source_branch` (optional bool) Indicates if the source branch of the merge request will be deleted after merge
430+
- `merge_request.source_branch` (string) Source branch of the merge request
431+
- `merge_request.source_branch_exists` (bool) Indicates if the source branch of the merge request exists
432+
- `merge_request.source_branch_protected` (bool) Indicates if the source branch is protected
433+
- `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
434+
- `merge_request.squash_on_merge` (bool) Indicates if the merge request will be squashed when merged
435+
- `merge_request.state` (string) State of the merge request
436+
- `merge_request.target_branch` (string) Target branch of the merge request
437+
- `merge_request.target_branch_exists` (bool) Indicates if the target branch of the merge request exists
438+
- `merge_request.time_between_first_and_last_commit` (optional duration)
439+
- `merge_request.time_since_first_commit` (optional duration)
440+
- `merge_request.time_since_last_commit` (optional duration)
441+
- `merge_request.title` (string) Title of the merge request
442+
- `merge_request.updated_at` (time) Timestamp of when the merge request was last updated
443+
- `merge_request.upvotes` (int) Number of upvotes for the merge request.
444+
- `merge_request.user_discussions_count` (optional int) Number of user discussions in the merge request
445+
- `merge_request.user_notes_count` (optional int) User notes count of the merge request
446+
- `project.archived` (bool) Indicates the archived status of the project
447+
- `project.created_at` (time) Timestamp of the project creation
448+
- `project.description` (string) Short description of the project
449+
- `project.full_path` (string) Full path of the project
450+
- `project.id` (string) ID of the project
451+
- `project.issues_enabled` (bool) Indicates if Issues are enabled for the current user
452+
- `project.labels[].color` (string) Background color of the label
453+
- `project.labels[].description` (string) Description of the label (Markdown rendered as HTML for caching)
454+
- `project.labels[].id` (string) Label ID
455+
- `project.labels[].title` (string) Content of the label
456+
- `project.last_activity_at` (time) Timestamp of the project last activity
457+
- `project.name` (string) Name of the project (without namespace)
458+
- `project.name_with_namespace` (string) Full name of the project with its namespace
459+
- `project.path` (string) Path of the project
460+
- `project.topics` ([]string) List of project topics
461+
- `project.visibility` (string) Visibility of the project
471462

472463
### Functions
473464

pkg/scm/gitlab/context.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func NewContext(ctx context.Context, baseURL, token string) (*Context, error) {
5757
if len(evalContext.MergeRequest.ResponseFirstCommits.Nodes) > 0 {
5858
evalContext.MergeRequest.FirstCommit = &evalContext.MergeRequest.ResponseFirstCommits.Nodes[0]
5959

60-
tmp := time.Since(evalContext.MergeRequest.FirstCommit.CommittedDate)
60+
tmp := time.Since(*evalContext.MergeRequest.FirstCommit.CommittedDate)
6161
evalContext.MergeRequest.TimeSinceFirstCommit = &tmp
6262
}
6363

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

69-
tmp := time.Since(evalContext.MergeRequest.LastCommit.CommittedDate)
69+
tmp := time.Since(*evalContext.MergeRequest.LastCommit.CommittedDate)
7070
evalContext.MergeRequest.TimeSinceLastCommit = &tmp
7171
}
7272

7373
evalContext.MergeRequest.ResponseLastCommits = nil
7474

7575
if evalContext.MergeRequest.FirstCommit != nil && evalContext.MergeRequest.LastCommit != nil {
76-
tmp := evalContext.MergeRequest.FirstCommit.CommittedDate.Sub(evalContext.MergeRequest.LastCommit.CommittedDate).Round(time.Hour)
76+
tmp := evalContext.MergeRequest.FirstCommit.CommittedDate.Sub(*evalContext.MergeRequest.LastCommit.CommittedDate).Round(time.Hour)
7777
evalContext.MergeRequest.TimeBetweenFirstAndLastCommit = &tmp
7878
}
7979

schema/docs.tmpl

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{- define "attributes" -}}
2+
{{- range .Attributes -}}
3+
{{ if .IsCustomType -}}{{- template "attributes" . }}{{- else }}
4+
- `{{ .BlockName }}` ({{ if .Optional }}optional {{ end }}{{ .Type }}) {{ .Description }}{{- end -}}
5+
{{- end }}
6+
{{- end -}}
7+
8+
### Attributes
9+
{{ template "attributes" . -}}

schema/generate.go

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package schema
2+
3+
//go:generate go run gitlab.go

0 commit comments

Comments
 (0)