Skip to content
This repository was archived by the owner on Aug 28, 2023. It is now read-only.

Commit 04f27a8

Browse files
committed
Merge branch 'tvon-github-enterprise'
2 parents 962ca02 + 3ffc197 commit 04f27a8

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/sentry_github/plugin.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,28 @@
1616

1717

1818
class GitHubOptionsForm(forms.Form):
19-
# TODO: validate repo?
20-
repo = forms.CharField(label=_('Repository Name'),
21-
widget=forms.TextInput(attrs={'placeholder': 'e.g. getsentry/sentry'}),
22-
help_text=_('Enter your repository name, including the owner.'))
19+
repo = forms.CharField(
20+
label=_('Repository Name'),
21+
widget=forms.TextInput(attrs={'placeholder': 'e.g. getsentry/sentry'}),
22+
help_text=_('Enter your repository name, including the owner.'))
23+
endpoint = forms.CharField(
24+
label=_('GitHub API Endpoint'),
25+
widget=forms.TextInput(attrs={'placeholder': 'https://api.github.com'}),
26+
initial='https://api.github.com',
27+
help_text=_('Enter the base URL to the GitHub API.'))
28+
github_url = forms.CharField(
29+
label=_('GitHub Base URL'),
30+
widget=forms.TextInput(attrs={'placeholder': 'https://github.com'}),
31+
initial='https://github.com',
32+
help_text=_('Enter the base URL to the GitHub for generating issue links.'))
33+
34+
def clean_endpoint(self):
35+
data = self.cleaned_data['endpoint']
36+
return data.rstrip('/')
37+
38+
def clean_github_url(self):
39+
data = self.cleaned_data['github_url']
40+
return data.rstrip('/')
2341

2442

2543
class GitHubPlugin(IssuePlugin):
@@ -52,8 +70,9 @@ def create_issue(self, request, group, form_data, **kwargs):
5270
raise forms.ValidationError(_('You have not yet associated GitHub with your account.'))
5371

5472
repo = self.get_option('repo', group.project)
73+
endpoint = self.get_option('endpoint', group.project) or 'https://api.github.com'
5574

56-
url = 'https://api.github.com/repos/%s/issues' % (repo,)
75+
url = '%s/repos/%s/issues' % (endpoint, repo,)
5776

5877
json_data = {
5978
"title": form_data['title'],
@@ -93,5 +112,6 @@ def get_issue_label(self, group, issue_id, **kwargs):
93112
def get_issue_url(self, group, issue_id, **kwargs):
94113
# XXX: get_option may need tweaked in Sentry so that it can be pre-fetched in bulk
95114
repo = self.get_option('repo', group.project)
115+
github_url = self.get_option('github_url', group.project) or 'https://github.com'
96116

97-
return 'https://github.com/%s/issues/%s' % (repo, issue_id)
117+
return '%s/%s/issues/%s' % (github_url, repo, issue_id)

0 commit comments

Comments
 (0)