Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: generate countries.tsx from Go code#15274

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ammario merged 11 commits intocoder:mainfromjoobisb:issue#15074
Nov 15, 2024

Conversation

joobisb
Copy link
Contributor

Closes#15074

We have a hard-coded list of countries athttps://github.com/coder/coder/blob/main/site/src/pages/SetupPage/countries.tsx. This means Go code in coder/coder doesn't have an easy way of utilizing it.

Solution

Generate countries.tsx from Go code. Generated byscripts/apitypings

@cdr-botcdr-botbot added the communityPull Requests and issues created by the community. labelOct 29, 2024
@joobisb
Copy link
ContributorAuthor

@johnstcn@dannykopping please do have a look

Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good from my end, some linter issues.

Could you add an exaple prompt comand (seecli/prompts.go)?

This will let us validate country selection more easily (e.g.go run ./cmd/coder exp prompt-example country)

cc@BrunoQuaresma for FE review

joobisb reacted with thumbs up emoji
@@ -51,3 +52,36 @@ func TestGeneration(t *testing.T) {
})
}
}

func TestGenerateSliceOfObjectsTypeScript(t *testing.T) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
t.Parallel()

joobisb reacted with thumbs up emoji
Comment on lines 62 to 69

countriesTS, err := generateSliceOfObjectsTypeScript("countries", codersdk.Countries)
if err != nil {
log.Fatal(ctx, fmt.Sprintf("generate countries typeScript: %s", err.Error()))
}
_, _ = fmt.Print("// The code below is generated from codersdk/countries.go.\n")
_, _ = fmt.Print(countriesTS, "\n")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

To do this correctly, we should not have to specifycodersdk.Countries. We should implement it here:

case*types.Var:
// TODO: Are any enums var declarations? This is also codersdk.Me.

I feel a bit apprehensive to importcodersdk into this tool.

We could make it a new generator (:cry:) or actually auto-gen vars from the codersdk package (likecodersdk.Me).

If we do thevars, we might want to have some opt-in comment. Idk how many var declarations we have

joobisb reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We should really have a general autogen tool and pattern for these. When the types are in Go and no package AST parsing is necessary.

rbacgen is an example.

joobisb reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@Emyrk

got it, will implement a general autogen tool. As suggested, I'm thinking of doing it similar to howrbacgen is done.

So the autogen tool will be underscripts/valuegen which containsmain.go which is the script itself andtypescript.tstmpl which will be the TS template to which we will convert thecountries.go

varCountries= []Country{

If similar types conversion needs are needed in the future for other types in Go, it can be handled in the script to use the sametypescriptconst.tstmpl template or a different one based on the need.

does that make sense? wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@joobisb That all sounds reasonable. It'll probably throw into a different.ts file.

It would be awesome ifrbacgen andvaluegen could be merged into 1 😄

joobisb reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@Emyrk I have updated the scripts and have merged both into a singletypegen script, please do have a look

Emyrk reacted with thumbs up emoji
@dannykoppingdannykopping removed their request for reviewNovember 5, 2024 08:02
@joobisbjoobisb requested a review fromEmyrkNovember 9, 2024 17:51
Copy link
Member

@EmyrkEmyrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Perfect 👍

joobi-keyvalue reacted with heart emoji
@matifalimatifalienabled auto-merge (squash)November 13, 2024 07:47
auto-merge was automatically disabledNovember 13, 2024 14:16

Head branch was pushed to by a user without write access

@joobisb
Copy link
ContributorAuthor

@matifali could you please help to run the CI again and merge, I've fixed a formatting error

Emyrk reacted with thumbs up emoji

@Emyrk
Copy link
Member

I am unsure why that premium e2e is failing. I'll take a quick look

@matifali
Copy link
Member

@Emyrk Because PRs from forks do not have access to secrets.

@matifali
Copy link
Member

matifali commentedNov 13, 2024
edited
Loading

This could be solved by using,

on:pull_request_target:

The only downside is that the workflows are run from the target branch, but the code is checked out from the PR branch.

@Emyrk
Copy link
Member

@Emyrk Because PRs from forks do not have access to secrets.

Ahh, how do we get around this?@matifali

@joobisb
Copy link
ContributorAuthor

@Emyrk Because PRs from forks do not have access to secrets.

Ahh, how do we get around this?@matifali

@matifali@Emyrk

Do we have any workaround for this?

@matifali
Copy link
Member

@joobisb Thanks for the reminder. I will try something like the one below and let you know if it works.

This could be solved by using,

on:pull_request_target:

The only downside is that the workflows are run from the target branch, but the code is checked out from the PR branch.

@ammarioammario merged commit4cb8076 intocoder:mainNov 15, 2024
27 of 29 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@johnstcnjohnstcnjohnstcn left review comments

@EmyrkEmyrkEmyrk approved these changes

Assignees

@joobisbjoobisb

Labels
communityPull Requests and issues created by the community.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

chore: generate countries.tsx from Go code
5 participants
@joobisb@Emyrk@matifali@johnstcn@ammario

[8]ページ先頭

©2009-2025 Movatter.jp