(taskCtx plugin.TaskContext, options map[string]interface{})
| 152 | } |
| 153 | |
| 154 | func (p GithubGraphql) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]interface{}) (interface{}, errors.Error) { |
| 155 | logger := taskCtx.GetLogger() |
| 156 | logger.Debug("%v", options) |
| 157 | var op githubTasks.GithubOptions |
| 158 | err := helper.Decode(options, &op, nil) |
| 159 | if err != nil { |
| 160 | return nil, err |
| 161 | } |
| 162 | connectionHelper := helper.NewConnectionHelper( |
| 163 | taskCtx, |
| 164 | nil, |
| 165 | p.Name(), |
| 166 | ) |
| 167 | connection := &models.GithubConnection{} |
| 168 | err = connectionHelper.FirstById(connection, op.ConnectionId) |
| 169 | if err != nil { |
| 170 | return nil, errors.Default.Wrap(err, "unable to get github connection by the given connection ID: %v") |
| 171 | } |
| 172 | |
| 173 | apiClient, err := githubTasks.CreateApiClient(taskCtx, connection) |
| 174 | if err != nil { |
| 175 | return nil, errors.Default.Wrap(err, "unable to get github API client instance") |
| 176 | } |
| 177 | |
| 178 | err = githubImpl.EnrichOptions(taskCtx, &op, apiClient.ApiClient) |
| 179 | if err != nil { |
| 180 | return nil, err |
| 181 | } |
| 182 | |
| 183 | tokens := strings.Split(connection.Token, ",") |
| 184 | src := oauth2.StaticTokenSource( |
| 185 | &oauth2.Token{AccessToken: tokens[0]}, |
| 186 | ) |
| 187 | oauthContext := taskCtx.GetContext() |
| 188 | proxy := connection.GetProxy() |
| 189 | if proxy != "" { |
| 190 | pu, err := url.Parse(proxy) |
| 191 | if err != nil { |
| 192 | return nil, errors.Convert(err) |
| 193 | } |
| 194 | if pu.Scheme == "http" || pu.Scheme == "socks5" { |
| 195 | proxyClient := &http.Client{ |
| 196 | Transport: &http.Transport{Proxy: http.ProxyURL(pu)}, |
| 197 | } |
| 198 | oauthContext = context.WithValue( |
| 199 | taskCtx.GetContext(), |
| 200 | oauth2.HTTPClient, |
| 201 | proxyClient, |
| 202 | ) |
| 203 | logger.Debug("Proxy set in oauthContext to %s", proxy) |
| 204 | } else { |
| 205 | return nil, errors.BadInput.New("Unsupported scheme set in proxy") |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | httpClient := oauth2.NewClient(oauthContext, src) |
| 210 | endpoint, err := errors.Convert01(url.Parse(connection.Endpoint)) |
| 211 | if err != nil { |
nothing calls this directly
no test coverage detected