Skip to content

Commit 74a4adf

Browse files
authored
Merge branch 'master' into fix-python-attrs-preset
2 parents 0b94c86 + b38dd6c commit 74a4adf

File tree

9 files changed

+92
-56
lines changed

9 files changed

+92
-56
lines changed

.github/workflows/automerge-for-humans-merging.yml

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,69 @@ on:
1818

1919
jobs:
2020
automerge-for-humans:
21-
if: github.event.pull_request.draft == false && (github.event.pull_request.user.login != 'asyncapi-bot' || github.event.pull_request.user.login != 'dependabot[bot]' || github.event.pull_request.user.login != 'dependabot-preview[bot]') #it runs only if PR actor is not a bot, at least not a bot that we know
21+
# it runs only if PR actor is not a bot, at least not a bot that we know
22+
if: |
23+
github.event.pull_request.draft == false &&
24+
(github.event.pull_request.user.login != 'asyncapi-bot' ||
25+
github.event.pull_request.user.login != 'dependabot[bot]' ||
26+
github.event.pull_request.user.login != 'dependabot-preview[bot]')
2227
runs-on: ubuntu-latest
2328
steps:
24-
- name: Get list of authors
25-
uses: sergeysova/jq-action@v2
29+
- name: Get PR authors
2630
id: authors
31+
uses: actions/github-script@v7
2732
with:
28-
# This cmd does following (line by line):
29-
# 1. CURL querying the list of commits of the current PR via GH API. Why? Because the current event payload does not carry info about the commits.
30-
# 2. Iterates over the previous returned payload, and creates an array with the filtered results (see below) so we can work wit it later. An example of payload can be found in https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#webhook-payload-example-34.
31-
# 3. Grabs the data we need for adding the `Co-authored-by: ...` lines later and puts it into objects to be used later on.
32-
# 4. Filters the results by excluding the current PR sender. We don't need to add it as co-author since is the PR creator and it will become by default the main author.
33-
# 5. Removes repeated authors (authors can have more than one commit in the PR).
34-
# 6. Builds the `Co-authored-by: ...` lines with actual info.
35-
# 7. Transforms the array into plain text. Thanks to this, the actual stdout of this step can be used by the next Workflow step (wich is basically the automerge).
36-
cmd: |
37-
curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" "${{github.event.pull_request._links.commits.href}}?per_page=100" |
38-
jq -r '[.[]
39-
| {name: .commit.author.name, email: .commit.author.email, login: .author.login}]
40-
| map(select(.login != "${{github.event.pull_request.user.login}}"))
41-
| unique
42-
| map("Co-authored-by: " + .name + " <" + .email + ">")
43-
| join("\n")'
44-
multiline: true
33+
script: |
34+
// Get paginated list of all commits in the PR
35+
try {
36+
const commitOpts = github.rest.pulls.listCommits.endpoint.merge({
37+
owner: context.repo.owner,
38+
repo: context.repo.repo,
39+
pull_number: context.issue.number
40+
});
41+
42+
const commits = await github.paginate(commitOpts);
43+
return commits;
44+
} catch (error) {
45+
core.setFailed(error.message);
46+
return [];
47+
}
48+
49+
- name: Create commit message
50+
id: create-commit-message
51+
uses: actions/github-script@v7
52+
with:
53+
script: |
54+
const commits = ${{ steps.authors.outputs.result }};
55+
56+
if (commits.length === 0) {
57+
core.setFailed('No commits found in the PR');
58+
return '';
59+
}
60+
61+
// Get unique authors from the commits list
62+
const authors = commits.reduce((acc, commit) => {
63+
const username = commit.author?.login || commit.commit.author?.name;
64+
if (username && !acc[username]) {
65+
acc[username] = {
66+
name: commit.commit.author?.name,
67+
email: commit.commit.author?.email,
68+
}
69+
}
70+
71+
return acc;
72+
}, {});
73+
74+
// Create a string of the form "Co-authored-by: Name <email>"
75+
// ref: https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors
76+
const coAuthors = Object.values(authors).map(author => {
77+
return `Co-authored-by: ${author.name} <${author.email}>`;
78+
}).join('\n');
79+
80+
core.debug(coAuthors);;
81+
82+
return coAuthors;
83+
4584
- name: Automerge PR
4685
uses: pascalgn/automerge-action@22948e0bc22f0aa673800da838595a3e7347e584 #v0.15.6 https://github.com/pascalgn/automerge-action/releases/tag/v0.15.6
4786
env:
@@ -50,6 +89,6 @@ jobs:
5089
MERGE_METHOD: "squash"
5190
# Using the output of the previous step (`Co-authored-by: ...` lines) as commit description.
5291
# Important to keep 2 empty lines as https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors#creating-co-authored-commits-on-the-command-line mentions
53-
MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})\n\n\n${{ steps.authors.outputs.value }}"
92+
MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})\n\n\n${{ fromJSON(steps.create-commit-message.outputs.result) }}"
5493
MERGE_RETRIES: "20"
5594
MERGE_RETRY_SLEEP: "30000"

examples/generate-python-pydantic-models/__snapshots__/index.spec.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
exports[`Should be able to render python models and should log expected output to console: class-model 1`] = `
44
Array [
55
"class Root(BaseModel):
6-
optional_field: Optional[str] = Field(description='''this field is optional''', default=None, default=None)
6+
optional_field: Optional[str] = Field(description='''this field is optional''', default=None)
77
required_field: str = Field(description='''this field is required''')
8-
no_description: Optional[str] = Field(default=None, default=None)
9-
options: Optional[Options.Options] = Field(default=None, default=None)
10-
content_type: Optional[str] = Field(default=None, default=None)
8+
no_description: Optional[str] = Field(default=None)
9+
options: Optional[Options.Options] = Field(default=None)
10+
content_type: Optional[str] = Field(default=None)
1111
",
1212
]
1313
`;

modelina-cli/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ $ npm install -g @asyncapi/modelina-cli
162162
$ modelina COMMAND
163163
running command...
164164
$ modelina (--version)
165-
@asyncapi/modelina-cli/4.0.1 linux-x64 node-v18.20.6
165+
@asyncapi/modelina-cli/4.0.2 linux-x64 node-v18.20.6
166166
$ modelina --help [COMMAND]
167167
USAGE
168168
$ modelina COMMAND
@@ -240,7 +240,7 @@ DESCRIPTION
240240
CLI config settings
241241
```
242242

243-
_See code: [src/commands/config/index.ts](https://github.com/asyncapi/modelina/blob/v4.0.1/modelina-cli/src/commands/config/index.ts)_
243+
_See code: [src/commands/config/index.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/index.ts)_
244244

245245
## `modelina config context`
246246

@@ -254,7 +254,7 @@ DESCRIPTION
254254
Manage short aliases for full paths to inputs
255255
```
256256

257-
_See code: [src/commands/config/context/index.ts](https://github.com/asyncapi/modelina/blob/v4.0.1/modelina-cli/src/commands/config/context/index.ts)_
257+
_See code: [src/commands/config/context/index.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/index.ts)_
258258

259259
## `modelina config context add CONTEXT-NAME SPEC-FILE-PATH`
260260

@@ -276,7 +276,7 @@ DESCRIPTION
276276
Add a context to the store
277277
```
278278

279-
_See code: [src/commands/config/context/add.ts](https://github.com/asyncapi/modelina/blob/v4.0.1/modelina-cli/src/commands/config/context/add.ts)_
279+
_See code: [src/commands/config/context/add.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/add.ts)_
280280

281281
## `modelina config context current`
282282

@@ -293,7 +293,7 @@ DESCRIPTION
293293
Shows the current context that is being used
294294
```
295295

296-
_See code: [src/commands/config/context/current.ts](https://github.com/asyncapi/modelina/blob/v4.0.1/modelina-cli/src/commands/config/context/current.ts)_
296+
_See code: [src/commands/config/context/current.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/current.ts)_
297297

298298
## `modelina config context edit CONTEXT-NAME NEW-SPEC-FILE-PATH`
299299

@@ -314,7 +314,7 @@ DESCRIPTION
314314
Edit a context in the store
315315
```
316316

317-
_See code: [src/commands/config/context/edit.ts](https://github.com/asyncapi/modelina/blob/v4.0.1/modelina-cli/src/commands/config/context/edit.ts)_
317+
_See code: [src/commands/config/context/edit.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/edit.ts)_
318318

319319
## `modelina config context init [CONTEXT-FILE-PATH]`
320320

@@ -337,7 +337,7 @@ DESCRIPTION
337337
Initialize context
338338
```
339339

340-
_See code: [src/commands/config/context/init.ts](https://github.com/asyncapi/modelina/blob/v4.0.1/modelina-cli/src/commands/config/context/init.ts)_
340+
_See code: [src/commands/config/context/init.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/init.ts)_
341341

342342
## `modelina config context list`
343343

@@ -354,7 +354,7 @@ DESCRIPTION
354354
List all the stored contexts in the store
355355
```
356356

357-
_See code: [src/commands/config/context/list.ts](https://github.com/asyncapi/modelina/blob/v4.0.1/modelina-cli/src/commands/config/context/list.ts)_
357+
_See code: [src/commands/config/context/list.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/list.ts)_
358358

359359
## `modelina config context remove CONTEXT-NAME`
360360

@@ -374,7 +374,7 @@ DESCRIPTION
374374
Delete a context from the store
375375
```
376376

377-
_See code: [src/commands/config/context/remove.ts](https://github.com/asyncapi/modelina/blob/v4.0.1/modelina-cli/src/commands/config/context/remove.ts)_
377+
_See code: [src/commands/config/context/remove.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/remove.ts)_
378378

379379
## `modelina config context use CONTEXT-NAME`
380380

@@ -394,7 +394,7 @@ DESCRIPTION
394394
Set a context as current
395395
```
396396

397-
_See code: [src/commands/config/context/use.ts](https://github.com/asyncapi/modelina/blob/v4.0.1/modelina-cli/src/commands/config/context/use.ts)_
397+
_See code: [src/commands/config/context/use.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/config/context/use.ts)_
398398

399399
## `modelina generate LANGUAGE FILE`
400400

@@ -458,7 +458,7 @@ DESCRIPTION
458458
Generates typed models
459459
```
460460

461-
_See code: [src/commands/generate.ts](https://github.com/asyncapi/modelina/blob/v4.0.1/modelina-cli/src/commands/generate.ts)_
461+
_See code: [src/commands/generate.ts](https://github.com/asyncapi/modelina/blob/v4.0.2/modelina-cli/src/commands/generate.ts)_
462462

463463
## `modelina help [COMMAND]`
464464

modelina-cli/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modelina-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@asyncapi/modelina-cli",
33
"description": "CLI to work with Modelina",
4-
"version": "4.0.2",
4+
"version": "4.0.3",
55
"bin": {
66
"modelina": "./bin/run_bin"
77
},

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@asyncapi/modelina",
3-
"version": "4.0.2",
3+
"version": "4.0.3",
44
"description": "Library for generating data models based on inputs such as AsyncAPI, OpenAPI, or JSON Schema documents",
55
"license": "Apache-2.0",
66
"homepage": "https://www.modelina.org",

src/generators/python/presets/Pydantic.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ const PYTHON_PYDANTIC_CLASS_PRESET: ClassPresetType<PythonOptions> = {
5959
) {
6060
decoratorArgs.push('exclude=True');
6161
}
62-
if (!property.required) {
63-
decoratorArgs.push('default=None');
64-
}
6562

6663
return `${propertyName}: ${type} = Field(${decoratorArgs.join(', ')})`;
6764
},

test/generators/python/presets/__snapshots__/Pydantic.spec.ts.snap

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`PYTHON_PYDANTIC_PRESET should render nullable union 1`] = `
44
Array [
55
"class NullableUnionTest(BaseModel):
66
nullable_union_test: Optional[Union[Union1.Union1]] = Field(default=None)
7-
additional_properties: Optional[dict[str, Any]] = Field(default=None, exclude=True, default=None)
7+
additional_properties: Optional[dict[str, Any]] = Field(default=None, exclude=True)
88
99
@model_serializer(mode='wrap')
1010
def custom_serializer(self, handler):
@@ -40,8 +40,8 @@ Array [
4040
4141
",
4242
"class Union1(BaseModel):
43-
test_prop1: Optional[str] = Field(default=None, default=None)
44-
additional_properties: Optional[dict[str, Any]] = Field(default=None, exclude=True, default=None)
43+
test_prop1: Optional[str] = Field(default=None)
44+
additional_properties: Optional[dict[str, Any]] = Field(default=None, exclude=True)
4545
4646
@model_serializer(mode='wrap')
4747
def custom_serializer(self, handler):
@@ -84,8 +84,8 @@ exports[`PYTHON_PYDANTIC_PRESET should render pydantic for class 1`] = `
8484
prop: Optional[str] = Field(description='''test
8585
multi
8686
line
87-
description''', default=None, default=None)
88-
additional_properties: Optional[dict[str, Any]] = Field(default=None, exclude=True, default=None)
87+
description''', default=None)
88+
additional_properties: Optional[dict[str, Any]] = Field(default=None, exclude=True)
8989
9090
@model_serializer(mode='wrap')
9191
def custom_serializer(self, handler):
@@ -125,8 +125,8 @@ exports[`PYTHON_PYDANTIC_PRESET should render pydantic for class 1`] = `
125125
exports[`PYTHON_PYDANTIC_PRESET should render union to support Python < 3.10 1`] = `
126126
Array [
127127
"class UnionTest(BaseModel):
128-
union_test: Optional[Union[Union1.Union1, Union2.Union2]] = Field(default=None, default=None)
129-
additional_properties: Optional[dict[str, Any]] = Field(default=None, exclude=True, default=None)
128+
union_test: Optional[Union[Union1.Union1, Union2.Union2]] = Field(default=None)
129+
additional_properties: Optional[dict[str, Any]] = Field(default=None, exclude=True)
130130
131131
@model_serializer(mode='wrap')
132132
def custom_serializer(self, handler):
@@ -162,8 +162,8 @@ Array [
162162
163163
",
164164
"class Union1(BaseModel):
165-
test_prop1: Optional[str] = Field(default=None, default=None)
166-
additional_properties: Optional[dict[str, Any]] = Field(default=None, exclude=True, default=None)
165+
test_prop1: Optional[str] = Field(default=None)
166+
additional_properties: Optional[dict[str, Any]] = Field(default=None, exclude=True)
167167
168168
@model_serializer(mode='wrap')
169169
def custom_serializer(self, handler):
@@ -199,8 +199,8 @@ Array [
199199
200200
",
201201
"class Union2(BaseModel):
202-
test_prop2: Optional[str] = Field(default=None, default=None)
203-
additional_properties: Optional[dict[str, Any]] = Field(default=None, exclude=True, default=None)
202+
test_prop2: Optional[str] = Field(default=None)
203+
additional_properties: Optional[dict[str, Any]] = Field(default=None, exclude=True)
204204
205205
@model_serializer(mode='wrap')
206206
def custom_serializer(self, handler):

0 commit comments

Comments
 (0)