How to fetch a Repository from HTTP Request for user repositories (repositories that don't have projects created)

The Atlassian API for fetching the repository using repository service is repositoryService.getBySlug(project, slug);

But, it could also be a user’s repository that does not have a project. Example

http://ubox:7990/bitbucket/users/**kshi**/repos/kshitijrepo/commits/643ea6502e8bd8db70f9e62d920297ea1c9e4c65
getBySlug API below fails because this repository does not have any project created for it.

public Repository getRepository(HttpServletRequest req){

        String pathInfo = req.getPathInfo();
        String[] components = pathInfo.split("/");
        return repositoryService.getBySlug(components[2], components[4]);
}

How to get the repository for users like “kshi”?

There is another API that gives the repository getById(int id). Here the id is the repository ID.
How to fetch the id using the HTTPRequest to further fetch the repository?

@pvandevoorde could you help here ?

@bturner Any idea around this?

Apparently, the user name should be appended with a “~”.
For User Projects
i.e return repositoryService.getBySlug(“~”+components[2], components[4]);
Got to know about this from an older link…

It would be great if someone from Atlassian Staff can confirm this.
I too am in process of verifying this in my plugin.

I have verified this in my plugin.
I could correctly fetch Repository Name: KshitijRepo and Project Name:kshi
Below code worked for me.


public Repository getRepository(HttpServletRequest req){        
  String pathInfo = req.getPathInfo();
  String[] components = pathInfo.split("/");

  if(components[2].matches("users")){
      return repositoryService.getBySlug("~"+components[3],components[5]);
  }
  return repositoryService.getBySlug(components[3], components[5]);
}