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 support for GitHub-hosted runner API endpoints #3487

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

atilsensalduz
Copy link
Contributor

@atilsensalduz atilsensalduz commented Feb 20, 2025

This pull request introduces support for the GitHub-hosted runner API endpoints in the go-github library, addressing Issue #3461.

Changes Include:

  • Implementation of API endpoints for managing GitHub-hosted runners.
  • Support for the following operations:
  • Create a new hosted runner.
  • Update existing hosted runner details.
  • Delete a hosted runner.
  • Retrieve details of hosted runners.
  • Corresponding unit tests for each operation.

Additional Information:
API Reference: GitHub REST API: Hosted Runners.

Please let me know if any additional changes or improvements are needed!

Fixes: #3461.

Implement new methods for managing GitHub-hosted runners,
including functionalities for creating, updating, deleting, and
retrieving details about hosted runners.

References:
- GitHub REST API: https://docs.github.com/en/rest/actions/hosted-runners

Signed-off-by: atilsensalduz <[email protected]>
Copy link

google-cla bot commented Feb 20, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Implement new methods for managing GitHub-hosted runners,
including functionalities for creating, updating, deleting, and
retrieving details about hosted runners.

References:
- GitHub REST API: https://docs.github.com/en/rest/actions/hosted-runners

Signed-off-by: atilsensalduz <[email protected]>
@gmlewis gmlewis changed the title feat(actions): add support for GitHub-hosted runner API endpoints feat: Add support for GitHub-hosted runner API endpoints Feb 20, 2025
Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 98.96194% with 3 lines in your changes missing coverage. Please review.

Project coverage is 91.18%. Comparing base (868f897) to head (65910b7).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
github/actions_hosted_runners.go 98.08% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3487      +/-   ##
==========================================
+ Coverage   91.02%   91.18%   +0.15%     
==========================================
  Files         179      181       +2     
  Lines       15561    15863     +302     
==========================================
+ Hits        14165    14464     +299     
- Misses       1223     1225       +2     
- Partials      173      174       +1     

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

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, @atilsensalduz !
This is looking great!
There are a few minor tweaks, please, then we should be ready for a second LGTM+Approval from any other contributor to this repo before merging.

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Feb 20, 2025
Implement new methods for managing GitHub-hosted runners,
including functionalities for creating, updating, deleting, and
retrieving details about hosted runners.

References:
- GitHub REST API: https://docs.github.com/en/rest/actions/hosted-runners

Signed-off-by: atilsensalduz <[email protected]>
Implement new methods for managing GitHub-hosted runners,
including functionalities for creating, updating, deleting, and
retrieving details about hosted runners.

References:
- GitHub REST API: https://docs.github.com/en/rest/actions/hosted-runners

Signed-off-by: atilsensalduz <[email protected]>
Implement new methods for managing GitHub-hosted runners,
including functionalities for creating, updating, deleting, and
retrieving details about hosted runners.

References:
- GitHub REST API: https://docs.github.com/en/rest/actions/hosted-runners

Signed-off-by: atilsensalduz <[email protected]>
Implement new methods for managing GitHub-hosted runners,
including functionalities for creating, updating, deleting, and
retrieving details about hosted runners.

References:
- GitHub REST API: https://docs.github.com/en/rest/actions/hosted-runners

Signed-off-by: atilsensalduz <[email protected]>
Implement new methods for managing GitHub-hosted runners,
including functionalities for creating, updating, deleting, and
retrieving details about hosted runners.

References:
- GitHub REST API: https://docs.github.com/en/rest/actions/hosted-runners

Signed-off-by: atilsensalduz <[email protected]>
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, @atilsensalduz!
LGTM.

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

@stevehipwell - might you have time for a code review? Thank you!

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.

This looks great @atilsensalduz. My only question is about the distinction between the CreateHostedRunnerRequest and UpdateHostedRunnerRequest. AFAIK the idiom in the codebase is to use a single struct where possible so this differs from that pattern. Personally I like this pattern but I'm interested if @gmlewis has some overarching guidance here?

In this specific case the difference between the two models should be removed when the API catches up with the UI behaviour. So maybe a shared HostedRunnerRequest struct with an error thrown if size is set for the update until the API supports it? Or maybe a comment in code to switch to aliases when the API matches. I guess the approach here probably comes back to the question above.

@gmlewis
Copy link
Collaborator

gmlewis commented Feb 25, 2025

This looks great @atilsensalduz. My only question is about the distinction between the CreateHostedRunnerRequest and UpdateHostedRunnerRequest. AFAIK the idiom in the codebase is to use a single struct where possible so this differs from that pattern. Personally I like this pattern but I'm interested if @gmlewis has some overarching guidance here?

Good catch, @stevehipwell.

We attempt to minimize the creation of extra structs and reuse similar structs for similar use cases with comments where necessary to explain usage.

…add validation

Unified the CreateHostedRunnerRequest and UpdateHostedRunnerRequest into a single HostedRunnerRequest struct.
Added validation functions for HostedRunnerRequest.

Signed-off-by: atilsensalduz <[email protected]>
@atilsensalduz
Copy link
Contributor Author

This looks great @atilsensalduz. My only question is about the distinction between the CreateHostedRunnerRequest and UpdateHostedRunnerRequest. AFAIK the idiom in the codebase is to use a single struct where possible so this differs from that pattern. Personally I like this pattern but I'm interested if @gmlewis has some overarching guidance here?

In this specific case the difference between the two models should be removed when the API catches up with the UI behaviour. So maybe a shared HostedRunnerRequest struct with an error thrown if size is set for the update until the API supports it? Or maybe a comment in code to switch to aliases when the API matches. I guess the approach here probably comes back to the question above.

@stevehipwell Thank you so much for the review and the excellent suggestion. I’ve implemented it along with the additional validations. I really appreciate your valuable input!

…add validation

Unified the CreateHostedRunnerRequest and UpdateHostedRunnerRequest into a single HostedRunnerRequest struct.
Added validation functions for HostedRunnerRequest.

Signed-off-by: atilsensalduz <[email protected]>
…add validation

Unified the CreateHostedRunnerRequest and UpdateHostedRunnerRequest into a single HostedRunnerRequest struct.
Added validation functions for HostedRunnerRequest.

Signed-off-by: atilsensalduz <[email protected]>
@gmlewis
Copy link
Collaborator

gmlewis commented Feb 25, 2025

@atilsensalduz - please run step 4 of CONTRIBUTING.md and make sure the linter and all tests pass locally, then push the changes to this PR. Thank you!

@atilsensalduz
Copy link
Contributor Author

@atilsensalduz - please run step 4 of CONTRIBUTING.md and make sure the linter and all tests pass locally, then push the changes to this PR. Thank you!

Hey @gmlewis , yes, all tests passed locally. The workflow is showing a failure in the TestRepositoriesService_IsCollaborator_True test, which I didn't modify. I believe this might be a flaky test. Could you please rerun the workflow? I thought this was already a known issue, but if needed, I’d be happy to investigate and fix this flaky test

@gmlewis
Copy link
Collaborator

gmlewis commented Feb 25, 2025

Hey @gmlewis , yes, all tests passed locally. The workflow is showing a failure in the TestRepositoriesService_IsCollaborator_True test, which I didn't modify. I believe this might be a flaky test. Could you please rerun the workflow? I thought this was already a known issue, but if needed, I’d be happy to investigate and fix this flaky test

Ah, very interesting! We've had some issues with GitHub Actions workflow runs lately, so if this is a flaky test it has probably been masked by these other issues... but more likely it was a GHA glitch.
It looks like the rerun worked fine. Sorry for the noise.

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, @atilsensalduz!
After a few tweaks, please, we should be ready for a second LGTM+Approval from any other contributor to this repo.

func (s *ActionsService) CreateHostedRunner(ctx context.Context, org string, request *HostedRunnerRequest) (*HostedRunner, *Response, error) {
err := validateCreateHostedRunnerRequest(request)
if err != nil {
return nil, nil, errors.New("validation failed: " + err.Error())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return nil, nil, errors.New("validation failed: " + err.Error())
return nil, nil, errors.New("validation failed: %w", err)

func (s *ActionsService) UpdateHostedRunner(ctx context.Context, org string, runnerID int64, updateReq HostedRunnerRequest) (*HostedRunner, *Response, error) {
err := validateUpdateHostedRunnerRequest(&updateReq)
if err != nil {
return nil, nil, errors.New("validation failed: " + err.Error())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return nil, nil, errors.New("validation failed: " + err.Error())
return nil, nil, errors.New("validation failed: %w", err)

Comment on lines +46 to +47
err := validateCreateHostedRunnerRequest(request)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
err := validateCreateHostedRunnerRequest(request)
if err != nil {
if err := validateCreateHostedRunnerRequest(request); err != nil {

func (s *EnterpriseService) CreateHostedRunner(ctx context.Context, enterprise string, request *HostedRunnerRequest) (*HostedRunner, *Response, error) {
err := validateCreateHostedRunnerRequest(request)
if err != nil {
return nil, nil, errors.New("validation failed: " + err.Error())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return nil, nil, errors.New("validation failed: " + err.Error())
return nil, nil, errors.New("validation failed: %w", err)

Comment on lines +198 to +199
err := validateUpdateHostedRunnerRequest(&updateReq)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
err := validateUpdateHostedRunnerRequest(&updateReq)
if err != nil {
if err := validateUpdateHostedRunnerRequest(&updateReq); err != nil {

func (s *EnterpriseService) UpdateHostedRunner(ctx context.Context, enterprise string, runnerID int64, updateReq HostedRunnerRequest) (*HostedRunner, *Response, error) {
err := validateUpdateHostedRunnerRequest(&updateReq)
if err != nil {
return nil, nil, errors.New("validation failed: " + err.Error())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return nil, nil, errors.New("validation failed: " + err.Error())
return nil, nil, errors.New("validation failed: %w", err)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsReview PR is awaiting a review before merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for actions/hosted-runners endpoints
3 participants