Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Bad repo assumption #16

Closed
jmgasper opened this issue Jun 14, 2018 · 11 comments
Closed

Bad repo assumption #16

jmgasper opened this issue Jun 14, 2018 · 11 comments

Comments

@jmgasper
Copy link
Collaborator

This chunk of code is causing some problems:

    const getRepoDetail = function (repoUrl, callback, errorCallBack) {
      $scope.$broadcast('alert.ClearAll', {});
      if (repoUrl.endsWith('/')) {
        repoUrl = repoUrl.slice(0, -1);
      }
      const results = repoUrl.split('/');
      $scope.repoName = results[results.length - 1];
      $scope.repoOwner = results[results.length - 2];
      $scope.repoType = results[results.length - 3].split('.')[0];
      ProjectService.getUserToken($scope.repoOwner, $scope.repoType).then(function (response) {
        if (angular.isDefined(response.data.token)) {
          $scope.token = response.data.token;
          return callback();
        } else {
          const erroMessage = 'Token not found for the user ' + $scope.repoOwner + ' of type ' + $scope.repoType + ' please complete profile setting';
          Alert.error(erroMessage, $scope);
        }
      }, function (error) {
        errorCallBack(error);
      });
    };

We can't assume that the "repoOwner" username is in the middle of the URL. For instance, consider the case of this actual project URL:

https://github.com/topcoder-platform/topcoder-x-ui

I would never be able to use TC-X to set up labels or webhooks here because it will try to use "topcoder-platform" as the owner username.

We need to do better here and use the credentials for the logged in user for Github and Gitlab directly - not attempting to do this strange manipulation.

jmgasper added a commit that referenced this issue Jun 18, 2018
@jmgasper
Copy link
Collaborator Author

@veshu - I'm still not seeing this one working:

2018-06-20T19:45:28.969863+00:00 heroku[router]: at=info method=POST path="/api/v1/projects/label" host=x.topcoder-dev.com request_id=a2db5f27-d8e4-457f-a0b0-dcdf4757fd07 fwd="76.30.121.49" dyno=web.1 connect=1ms service=151ms status=500 bytes=331 protocol=http
2018-06-20T19:45:28.968997+00:00 app[web.1]: error: Error happened in ProjectController#createLabel
2018-06-20T19:45:28.969006+00:00 app[web.1]: ApiError: Failed to create labels.. Not Found.
2018-06-20T19:45:28.969010+00:00 app[web.1]: at Object.createLabel (/app/src/services/ProjectService.js:166:22)
2018-06-20T19:45:28.969009+00:00 app[web.1]: at Object.convertGitHubError (/app/src/common/helper.js:138:20)
2018-06-20T19:45:28.969013+00:00 app[web.1]: at <anonymous>
2018-06-20T19:45:28.969015+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:188:7)
2018-06-20T19:45:31.202361+00:00 app[web.1]: error: Error happened in ProjectController#createHook
2018-06-20T19:45:31.202378+00:00 app[web.1]: ApiError: Failed to create webhook.. Not Found.
2018-06-20T19:45:31.202380+00:00 app[web.1]: at Object.convertGitHubError (/app/src/common/helper.js:138:20)
2018-06-20T19:45:31.202382+00:00 app[web.1]: at Object.createHook (/app/src/services/ProjectService.js:248:22)
2018-06-20T19:45:31.202384+00:00 app[web.1]: at <anonymous>
2018-06-20T19:45:31.202386+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:188:7)

screen shot 2018-06-20 at 2 47 11 pm

@veshu
Copy link
Contributor

veshu commented Jun 20, 2018

@jmgasper That must be due of extra url segments after url name. Can you please try remove issues/16 and add valid url. Or we need to handle such validation as well?

@jmgasper
Copy link
Collaborator Author

Ah, my bad. I'll retest

@jmgasper
Copy link
Collaborator Author

Still not working.

screen shot 2018-06-20 at 10 01 28 pm

@veshu
Copy link
Contributor

veshu commented Jun 21, 2018

I am suspecting something else is wrong, it is working fine on my tests. Could it be some issue related to permission? When i tried topcoder-x-ui repo URL i am getting same error while it looks on my test setup. also, Github doesn't provide much info when auth is failed.

image

@jmgasper
Copy link
Collaborator Author

Why would auth fail? It works as expected on other repos, under my "jmgasper" group, but not ones I've created elsewhere.

What does that error mean about ". Not Found"? Is that coming from our code or Github?

@veshu
Copy link
Contributor

veshu commented Jun 21, 2018

@jmgasper auth means permission here.
that error is comming from Github, I have checked full response from github, it is only returning not found error.

@jmgasper
Copy link
Collaborator Author

Can you add a sample request please? I'll look at that and see if I can run it outside TC-X

@veshu
Copy link
Contributor

veshu commented Jun 21, 2018

You can try this one check your token.

curl -X POST \
  'https://api.github.com/repos/veshu/tcxtest/labels?access_token=<your_token>' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -H 'Postman-Token: 752bca90-b2bb-4ee0-b32f-c83b9d92e2d2' \
  -d '{
  "name": "bug1",
  "description": "Houston, we have a problem",
  "color": "f29513"
}'

@jmgasper
Copy link
Collaborator Author

@veshu - I think I tracked down the problem - thanks for the sample. My OAuth2 application for Github doesn't have access to the "topcoder-platform" group, which is why the calls are failing. The "Not Found" is because the repo link isn't accessible with the given token.

It's confusing because I can go into the project on Github and set and remove labels just fine manually, and I expected to be able to do the same with the API, but it looks like we may have to tweak some settings.

Sorry for the confusion on this one.

@jmgasper
Copy link
Collaborator Author

@veshu - Tested this again after the fix to the permissions and it looks to be working, thanks!

jmgasper pushed a commit that referenced this issue Oct 9, 2019
jmgasper added a commit that referenced this issue Oct 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants