0

I'm trying to get some information about the current Github Repo Projects, for a VsCode Extension, But I don't know (Haven't found it in the Documentation) how to get the current Repo name. With that information, I would try to execute the following (Which I got from the documentation & works when I hard code a rep name as a string).

return await octokit.rest.projects
  .listForRepo({
    owner: userInfo.data.login,
    repo: currentRepoName,
  });
Felix Niedermann
  • 321
  • 3
  • 18
  • what context information do you have with the VS Code extension from which you could derive the repository name? – Gregor Sep 10 '21 at 16:24
  • I'm not sure I understand... – Felix Niedermann Sep 10 '21 at 16:47
  • I'm trying to understand your question, too :) When you say "current Repo", what do you mean? Current repository in the context of what exactly? – Gregor Sep 10 '21 at 20:03
  • In the folder when you open a git repo/folder in VsCode. I’m playing around with creating an Vs ode extension which gets some information about the repo your working on. – Felix Niedermann Sep 11 '21 at 10:30
  • Like the extension Git Lense, how does it know which repo it has to show the data from. – Felix Niedermann Sep 12 '21 at 06:55
  • I can get the current folder, but the folder doesn't have to have the same name like a git repo (I think, or am I wrong?) – Felix Niedermann Sep 12 '21 at 12:34
  • 2
    The source code for Git Lince is public, so you can check out how they are doing it? https://github.com/eamodio/vscode-gitlens I'd assume the look into `.git/config` and use the configuration for `origin` in your git remotes – Gregor Sep 13 '21 at 19:42
  • Yeah I was a bit dumb...I thought the hidden directories are shown in VsCode, but in the settigns of Vscode it exactly hides the .git directory. It was my first I idea to read it out of there but I thought it didn't exist xD. Now I read the file & with regex I get the repo name from the remote url (Maybe there's a better solution but it works for now). Thank you for making me look/think again. – Felix Niedermann Sep 15 '21 at 05:38

1 Answers1

0

Thanks to the help of @Gregor I got the following solution know. It's not quite pretty, so I'm still happy for any suggestions:

let file = await fs.readFileSync(require("path").resolve(__dirname, '../.git/config'), 'utf8');
let repo = (file.match('[^\/]+(\.git)')!)[0].toString().replace(".git", "");
Felix Niedermann
  • 321
  • 3
  • 18