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

feat: Add manage_ghes endpoints introduced in 3.15 #3433

Merged
merged 22 commits into from
Jan 21, 2025

Conversation

s4mur4i
Copy link
Contributor

@s4mur4i s4mur4i commented Jan 15, 2025

Fixes: #3415.

@gmlewis gmlewis changed the title feat: Adding manage_ghes endpoints introduced in 3.15 feat: Add manage_ghes endpoints introduced in 3.15 Jan 15, 2025
Copy link

codecov bot commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 94.00000% with 15 lines in your changes missing coverage. Please review.

Project coverage is 92.29%. Comparing base (4510383) to head (b07fc10).
Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
github/enterprise_manage_ghes.go 88.88% 4 Missing and 2 partials ⚠️
github/enterprise_manage_ghes_config.go 95.16% 4 Missing and 2 partials ⚠️
github/enterprise_manage_ghes_maintenance.go 90.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3433      +/-   ##
==========================================
+ Coverage   92.26%   92.29%   +0.02%     
==========================================
  Files         174      178       +4     
  Lines       15023    15273     +250     
==========================================
+ Hits        13861    14096     +235     
- Misses       1068     1078      +10     
- Partials       94       99       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 15, 2025

Please run ./script/generate.sh and ./script/fmt.sh and push the changes to this PR. Thanks.

@s4mur4i
Copy link
Contributor Author

s4mur4i commented Jan 15, 2025

Please run ./script/generate.sh and ./script/fmt.sh and push the changes to this PR. Thanks.

Strangely it doesn't show any diff for me:

➜  go-github git:(master) ./script/generate.sh                                                                
➜  go-github git:(master) ./script/fmt.sh                                                                     
➜  go-github git:(master) git status                                                                         
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Even lint shows no diff:

➜  go-github git:(master) ./script/lint.sh                                                                   
linting .
linting example
linting scrape
linting tools
validating generated files

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 15, 2025

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @s4mur4i .

This is a very large PR, and it looks like there are going to be many things to address, so I'll stop my review here and hopefully we will get the linting issues worked out.

Please see CONTRIBUTING.md for more helpful information.

github/enterprise_manage_ghes.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes.go Show resolved Hide resolved
@s4mur4i
Copy link
Contributor Author

s4mur4i commented Jan 15, 2025

Can you see this? https://github.com/google/go-github/actions/runs/12794271004/job/35672748807?pr=3433

Yes, I can. I don't really understand why I don't see change.

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 15, 2025

Can you see this? https://github.com/google/go-github/actions/runs/12794271004/job/35672748807?pr=3433

Yes, I can. I don't really understand why I don't see change.

One thing that I don't typically see in PRs is that you didn't create a separate branch for this change, but instead stayed on "master". I'm not sure if that is a problem or not, but it is one thing I don't think I've ever seen before. Typically, after you fork a repo and want to create a PR, you create a new branch and perform your work on that branch, then make a pull request off of that branch. Maybe this is nothing... I don't know... it's just different.

@s4mur4i
Copy link
Contributor Author

s4mur4i commented Jan 15, 2025

Can you see this? https://github.com/google/go-github/actions/runs/12794271004/job/35672748807?pr=3433

Yes, I can. I don't really understand why I don't see change.

One thing that I don't typically see in PRs is that you didn't create a separate branch for this change, but instead stayed on "master". I'm not sure if that is a problem or not, but it is one thing I don't think I've ever seen before. Typically, after you fork a repo and want to create a PR, you create a new branch and perform your work on that branch, then make a pull request off of that branch. Maybe this is nothing... I don't know... it's just different.

I cloned in a new directory and worked. strange. but should be good now.

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Jan 15, 2025
@s4mur4i
Copy link
Contributor Author

s4mur4i commented Jan 16, 2025

@gmlewis Regarding generate. I dont know how to solve that issue.
I tried with one of my colleagues, and he has same output and behaviour.
I don't know if it might be because of mac-os.

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 16, 2025

@gmlewis Regarding generate. I dont know how to solve that issue. I tried with one of my colleagues, and he has same output and behaviour. I don't know if it might be because of mac-os.

Hmmm... very strange. I'm on a Mac too and have not seen this before.

@s4mur4i
Copy link
Contributor Author

s4mur4i commented Jan 16, 2025

I reinstalled go o match exact version:

go-github git:(master) ✗ go version                                                                                                                                                           
go version go1.22.10 darwin/arm64

Pushed the update.

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 16, 2025

@stevehipwell - @alexandear - @dnwe - @willnorris - with our recently changes to Go Toolchain settings, we are now seeing bizarre problems like this one where the tooling did not help out the developer and made for a frustrating formatting experience. GitHub Workflows linting conflicted with the developer linting.

We need to come up with a solution that doesn't hurt the developer experience and yet is easy to maintain moving forward.

@seruman
Copy link

seruman commented Jan 16, 2025

.. I tried with one of my colleagues, and he has same output and behaviour.

Colleague here! I've took a look at this and here're my findings;

SMTP struct has two fields; UserName and Username, looks like Github API returns both username and user_name 🤷

https://docs.github.com/[email protected]/rest/enterprise-admin/manage-ghes#get-the-ghes-settings

https://github.com/s4mur4i/go-github/blob/a6383545144dd8f98845c94f4c453c920cb82046/github/enterprise_manage_ghes_config.go#L241-L242

The issue seems to be, for both fields getter.sortVal generated to has same value, lower case receiver + field;

sortVal: strings.ToLower(receiverType) + "." + strings.ToLower(fieldName),

Since sort.Sort is not stable, it might sort these two getter's different on each run;

// Sort getters by ReceiverType.FieldName.
sort.Sort(byName(t.Getters))

@dnwe
Copy link
Contributor

dnwe commented Jan 16, 2025

@gmlewis I think #3436 is likely the required fix here

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 16, 2025

@s4mur4i - can you please manually make the changes from #3436 to this PR and see if that solves the problem for you?

@s4mur4i
Copy link
Contributor Author

s4mur4i commented Jan 16, 2025

I accidently did a merge commit, just wanted to fix a resolve conflict :(
I applied the fixes from Pr #3436

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 16, 2025

I accidently did a merge commit, just wanted to fix a resolve conflict :( I applied the fixes from Pr #3436

No worries about the merge commit in this repo. We always squash-and-merge and therefore always have a clean commit history. This is also why we ask people to please not use force-push in this repo, as it makes it much more difficult for reviewers to see what has changed since their last review.

@s4mur4i
Copy link
Contributor Author

s4mur4i commented Jan 16, 2025

As I see there is still lint error. I guess then the toolchain was not a fix for this case.

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 17, 2025

One question for myself. Contribution.md says not to use merge commit, but would say to do cherry-pick or rebase. I did a rebase to get the patch and to get latest state. but a rebase would require a force-push, I don't know of other way to do it.
Should I have just taken patch applied it manually, or is there any other method recommended?

While you are working on a PR, you don't need to worry about what the master branch is doing.
Just keep pushing commits to your PR and please do NOT force-push.

We ALWAYS use "Squash and merge" in this repo, so our commit history is always clean. Do a "git log" on this repo to see what I mean.

If you ever have conflicting changes and GitHub says that the PR needs updating, you can simply follow these steps:

  1. git checkout master
  2. git pull origin master
  3. git checkout my-custom-cool-branch-that-I-am-currently-working-on
  4. git merge master

If there are conflicts, I personally like to use git mergetool (with kdiff3 as my merge tool) and resolve all the conflicts and then finalize the resolution with the command git commit -sam 'git merge master'.

  1. git push origin my-custom-cool-branch-that-I-am-currently-working-on

This may add many commits to a PR, but in the end, it never matters because we always "Squash and merge".

Please let me know if any of this is not clear.

I tried to explain this clearly in CONTRIBUTING.md, but if it is still unclear, please send me a PR to clean up the wording so that it is super-easy to understand.
Thank you.

@s4mur4i
Copy link
Contributor Author

s4mur4i commented Jan 17, 2025

@gmlewis I have an interesting issue, which I don't fully understand why.
I am working on 2 Comments. I have following Patch:

git diff github/enterprise_manage_ghes.go                                                                                                                                           cost-cluster
diff --git a/github/enterprise_manage_ghes.go b/github/enterprise_manage_ghes.go
index 3ecf373f..f4e136d8 100644
--- a/github/enterprise_manage_ghes.go
+++ b/github/enterprise_manage_ghes.go
@@ -27,13 +27,13 @@ type ClusterStatus struct {

 // ClusterStatusNode represents the status of a cluster node.
 type ClusterStatusNode struct {
-	Hostname *string                       `json:"hostname,omitempty"`
-	Status   *string                       `json:"status,omitempty"`
-	Services []*ClusterStatusNodesServices `json:"services"`
+	Hostname *string                      `json:"hostname,omitempty"`
+	Status   *string                      `json:"status,omitempty"`
+	Services []*ClusterStatusNodesService `json:"services"`
 }

-// ClusterStatusNodesServices represents the status of a service running on a cluster node.
-type ClusterStatusNodesServices struct {
+// ClusterStatusNodesService represents the status of a service running on a cluster node.
+type ClusterStatusNodesService struct {
 	Status  *string `json:"status,omitempty"`
 	Name    *string `json:"name,omitempty"`
 	Details *string `json:"details,omitempty"`

When I run generate I get following error:

./script/generate.sh                                                                                                                                                                cost-cluster
no operations defined for ClusterStatusNodesService.GetDetails
no operations defined for ClusterStatusNodesService.GetName
no operations defined for ClusterStatusNodesService.GetStatus
github/github.go:8: running "../script/metadata.sh": exit status 1

Same thing happens when I edit ConnectionService
Do you have idea why it might happen? All other generates were successful, just these 2 are having issues.
In github-accessors.go I see files successfully generated:

git diff github/github-accessors.go                                                                                                                                                 cost-cluster
diff --git a/github/github-accessors.go b/github/github-accessors.go
index d7841914..a020bcb4 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -2527,7 +2527,7 @@ func (c *ClusterStatusNode) GetStatus() string {
 }

 // GetDetails returns the Details field if it's non-nil, zero value otherwise.
-func (c *ClusterStatusNodesServices) GetDetails() string {
+func (c *ClusterStatusNodesService) GetDetails() string {
 	if c == nil || c.Details == nil {
 		return ""
 	}
@@ -2535,7 +2535,7 @@ func (c *ClusterStatusNodesServices) GetDetails() string {
 }

 // GetName returns the Name field if it's non-nil, zero value otherwise.
-func (c *ClusterStatusNodesServices) GetName() string {
+func (c *ClusterStatusNodesService) GetName() string {
 	if c == nil || c.Name == nil {
 		return ""
 	}
@@ -2543,7 +2543,7 @@ func (c *ClusterStatusNodesServices) GetName() string {
 }

 // GetStatus returns the Status field if it's non-nil, zero value otherwise.
-func (c *ClusterStatusNodesServices) GetStatus() string {
+func (c *ClusterStatusNodesService) GetStatus() string {
 	if c == nil || c.Status == nil {
 		return ""
 	}

Even stranger if I change it to ClusterStatusNodesServicess it works, and also ClusterStatusNodesServic works.

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 17, 2025

#3437 was just merged into master - can you please try it out to see if that fixes the problems you are seeing?

@s4mur4i
Copy link
Contributor Author

s4mur4i commented Jan 17, 2025

#3437 was just merged into master - can you please try it out to see if that fixes the problems you are seeing?

This morning this got merged into my branch:
s4mur4i@d13c739
it is not working with it.

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 17, 2025

#3437 was just merged into master - can you please try it out to see if that fixes the problems you are seeing?

This morning this got merged into my branch: s4mur4i@d13c739 it is not working with it.

@alexandear - can you please comment?

@alexandear
Copy link
Contributor

alexandear commented Jan 20, 2025

@gmlewis I have an interesting issue, which I don't fully understand why. I am working on 2 Comments. I have following Patch:
...

When I run generate I get following error:

./script/generate.sh                                                                                                                                                                cost-cluster
no operations defined for ClusterStatusNodesService.GetDetails
no operations defined for ClusterStatusNodesService.GetName
no operations defined for ClusterStatusNodesService.GetStatus
github/github.go:8: running "../script/metadata.sh": exit status 1

Same thing happens when I edit ConnectionService

Even stranger if I change it to ClusterStatusNodesServicess it works, and also ClusterStatusNodesServic works.

The issue appears because the struct suffixed with Service. It's because generate.sh executes metadata.sh, see

//go:generate ../script/metadata.sh update-go

Every exported type where type name ends in Service, see
if !id.IsExported() || !fn.Name.IsExported() || !strings.HasSuffix(id.Name, "Service") {

Service type is a special type in go-github for grouping related API functions. Examples: IssuesService, EnterpriseService etc.

To workaround this, we can rename ClusterStatusNodesServices to ClusterStatusNodesServiceItem, ConnectionServices to ConnectionServiceItem.

@s4mur4i
Copy link
Contributor Author

s4mur4i commented Jan 20, 2025

@alexandear Thank you for the update. With your solution it worked.
@gmlewis I think all comments were fixed, please let me know if something is missing.
Should I resolve the comments or will you do after reviewing?

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 20, 2025

Should I resolve the comments or will you do after reviewing?

Feel free to resolve them or I can later. Either way is fine with me. 😁

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 20, 2025

@s4mur4i - I'm currently on my cell phone but should be able to review this later today.
In the meantime, would you mind reviewing other PRs in this repo that have the "Needs Review" label if you have time? Thank you!

@s4mur4i
Copy link
Contributor Author

s4mur4i commented Jan 20, 2025

I resolved the one where I added a fix.
Also I checked to see Needs Review tag.
One of them was last year October, you wrote, if they don't respond you will close the ticket. didn't see response or action there.
Another one, same October, also no response
And last one just got an update from Alexander.
I think all are handled, and currently no action?

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 20, 2025

I resolved the one where I added a fix. Also I checked to see Needs Review tag. One of them was last year October, you wrote, if they don't respond you will close the ticket. didn't see response or action there. Another one, same October, also no response And last one just got an update from Alexander. I think all are handled, and currently no action?

Please feel free to ping me on PRs or issues where you see inconsistencies like this. Thank you, @s4mur4i !

@gmlewis
Copy link
Collaborator

gmlewis commented Jan 20, 2025

Hey @stevehipwell - I haven't seen this in ages!!! Thank you for fixing this!!!

CodeCov-works-2025-01-20_11-37-40

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Half-way through the second file. Let's stop here so you can address another sweeping change I've requested to one-word struct names.

github/enterprise_manage_ghes.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_maintenance.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_maintenance.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_maintenance.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_maintenance.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_maintenance.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_config.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes.go Outdated Show resolved Hide resolved
github/enterprise_manage_ghes_maintenance.go Show resolved Hide resolved
github/enterprise_manage_ghes_ssh.go Show resolved Hide resolved
@s4mur4i
Copy link
Contributor Author

s4mur4i commented Jan 21, 2025

@gmlewis The breaking test I think is not related to my work?

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @s4mur4i!
LGTM.

Next time, we should ideally break up enormous PRs like this one into several smaller PRs.

Awaiting second LGTM+Approval from any other contributor to this repo before merging.

Copy link
Contributor

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

LGTM

@gmlewis gmlewis removed the NeedsReview PR is awaiting a review before merging. label Jan 21, 2025
@gmlewis
Copy link
Collaborator

gmlewis commented Jan 21, 2025

Thank you, @stevehipwell !
Merging.

@gmlewis gmlewis merged commit daaa51a into google:master Jan 21, 2025
7 checks passed
@s4mur4i
Copy link
Contributor Author

s4mur4i commented Jan 21, 2025

Thank you for the reviews, and help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing api for managing Github Enterprise Server
6 participants