|
16 | 16 |
|
17 | 17 |
|
18 | 18 | 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('/') |
23 | 41 |
|
24 | 42 |
|
25 | 43 | class GitHubPlugin(IssuePlugin): |
@@ -52,8 +70,9 @@ def create_issue(self, request, group, form_data, **kwargs): |
52 | 70 | raise forms.ValidationError(_('You have not yet associated GitHub with your account.')) |
53 | 71 |
|
54 | 72 | repo = self.get_option('repo', group.project) |
| 73 | + endpoint = self.get_option('endpoint', group.project) or 'https://api.github.com' |
55 | 74 |
|
56 | | - url = 'https://api.github.com/repos/%s/issues' % (repo,) |
| 75 | + url = '%s/repos/%s/issues' % (endpoint, repo,) |
57 | 76 |
|
58 | 77 | json_data = { |
59 | 78 | "title": form_data['title'], |
@@ -93,5 +112,6 @@ def get_issue_label(self, group, issue_id, **kwargs): |
93 | 112 | def get_issue_url(self, group, issue_id, **kwargs): |
94 | 113 | # XXX: get_option may need tweaked in Sentry so that it can be pre-fetched in bulk |
95 | 114 | repo = self.get_option('repo', group.project) |
| 115 | + github_url = self.get_option('github_url', group.project) or 'https://github.com' |
96 | 116 |
|
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