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

Support for GitHub Enterprise closes #70 #160

Merged
merged 6 commits into from
May 25, 2022

Conversation

mheiges
Copy link
Contributor

@mheiges mheiges commented May 6, 2022

Example query results

Results
Add example SQL query results here (please include the input queries as well)

@e-gineer
Copy link
Contributor

e-gineer commented May 6, 2022

Quick note that I'm excited to see support for GitHub enterprise - thanks @mheiges! Have wanted this for a long time, but didn't have the ability to test.

@mheiges
Copy link
Contributor Author

mheiges commented May 6, 2022

some sample queries run against GHE, mostly verifying that repository_full_name is correct.

steampipe query "select name, repository_full_name from github_search_code  where query = 'filename:build.Dockerfile path:automation/docker'"

+------------------+-------------------------------------------+
| name             | repository_full_name                      |
+------------------+-------------------------------------------+
| build.Dockerfile | myORG/myorg-ui                            |
| build.Dockerfile | myORG/myorg-rpm-service                   |
| build.Dockerfile | myORG/myorg-certification-service         |
| build.Dockerfile | myORG/myorg-report-service                |
steampipe query "select title, repository_full_name from github_search_issue  where query = 'is:open repo:myORG/myorg-foo-service'"
+-------------------------+-----------------------------+
| title                   | repository_full_name        |
+-------------------------+-----------------------------+
| yeah, this is a problem | myORG/myorg-foo-service     |
+-------------------------+-----------------------------+
steampipe query "select title, repository_full_name from github_search_pull_request  where query = 'is:open repo:myORG/myorg-foo-service'"
+----------------------------+-----------------------------+
| title                      | repository_full_name        |
+----------------------------+-----------------------------+
| build with lockfile        | myORG/myorg-foo-service     |
+----------------------------+-----------------------------+
steampipe query "select description, repository_full_name from github_search_label where repository_id = 3753 and query = 'bug'"
+-------------------------+-----------------------------+
| description             | repository_full_name        |
+-------------------------+-----------------------------+
| Something isn't working | myORG/myorg-foo-service     |
+-------------------------+-----------------------------+

@cbruno10 cbruno10 self-requested a review May 6, 2022 13:23
@cbruno10 cbruno10 linked an issue May 22, 2022 that may be closed by this pull request
Copy link
Contributor

@cbruno10 cbruno10 left a comment

Choose a reason for hiding this comment

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

@mheiges Sorry for the slight delay in reviewing this PR, I've added a few questions/suggestions, can you please have a look when you get a chance? Also, can you please resolve the merge conflicts? Thanks!

github/utils.go Outdated Show resolved Hide resolved
}

if token == "" {
panic("'token' must be set in the connection configuration. Edit your connection configuration file and then restart Steampipe")
panic("token must be configured")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a specific reason you changed the panic message? This is a fairly standard message we use in other plugins as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not make this change, this came from the github-enterprise-support branch

}

if token == "" {
panic("'token' must be set in the connection configuration. Edit your connection configuration file and then restart Steampipe")
panic("token must be configured")
//return nil, errors.New("token must be configured")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//return nil, errors.New("token must be configured")

github/utils.go Outdated Show resolved Hide resolved
uv3.Path = uv3.Path + "api/v3/"
}

conn, err = github.NewEnterpriseClient(uv3.String(), "", tc)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any future compatibility you're aware of that wouldn't work if we don't pass the upload URL when creating the client?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know. This came from the github-enterprise-support branch, I haven't explored the client requirements.

}

if uv3.String() != "https://api.github.com/" {
uv3.Path = uv3.Path + "api/v3/"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to include this, or does the go-github library automatically attach this suffix, per https://github.com/google/go-github/blob/a58d5f0adf74ef73aadaac476f7285afc77a3b43/github/github.go#L357-L364

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems to be needed. It does seem like the library should handle the suffix but it's not doing so. I don't know why offhand. This came from the github-enterprise-support branch, I haven't explored the client code.

uv3.Path = uv3.Path + "api/v3/"
}

conn, err = github.NewEnterpriseClient(uv3.String(), "", tc)
Copy link
Contributor

Choose a reason for hiding this comment

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

If someone sets base_url as https://github.com/api/v3`, does the enterprise client still work, or does it fail/have another behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

base_url = "https://api.github.com/ works.

base_url = https://github.com/api/v3 returns a 404 status for https://github.com/api/v3/api/v3/search/issues

rx := regexp.MustCompile(`(?s)` + regexp.QuoteMeta("github.com/") + `(.*?)` + regexp.QuoteMeta("/blob"))
replacer := strings.NewReplacer("github.com/", "", "/blob", "")
return replacer.Replace(rx.FindString(*code.HTMLURL)), nil
rx := regexp.MustCompile(`https?://.+?/(.+?)/blob`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tested this change (along with other github_search_* table changes) against a GitHub cloud instance for backward compatibility? I saw some query results in #160 (comment), but wasn't sure if those were for an enterprise or cloud instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the tests were against github.com (base_url = "https://api.github.com/) and GH Enterprise with custom hostname (base_url = "https://abc.xyz.gov/. I guess our GHE is Server, not Cloud - I'm not clear on the difference.

@cbruno10 cbruno10 merged commit eb4dcd3 into turbot:main May 25, 2022
@cbruno10
Copy link
Contributor

@mheiges Thank you for testing out this branch and making improvements to it as well! We've just released v0.15.0 of this plugin, which includes this PR. If you see any issues, please let us know.

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.

Support for GitHub Enterprise
3 participants