SpinlockLabs / github.dart

GitHub Client Library for Dart
https://pub.dev/packages/github
MIT License
405 stars 142 forks source link

RepositoryContent.content is always null #369

Closed 89pleasure closed 1 year ago

89pleasure commented 1 year ago

Library version: latest Flutter: 3.7.11 Dart: 2.19.6

Hey there, I'm having an issue using the library. Trying to get the content of a file. I simply go through a folder tree and look for a certain file inside of the folder. If found I want to parse the yaml file. But the content of the file is always null.

What I do:

RepositoryContents modsFolder =await GithubService.instance.getRepositoryContent('Mods');
    if (modsFolder.isDirectory) {
      modsFolder.tree?.forEach(
        (modFolder) async {
          RepositoryContents modContent = await GithubService.instance
              .getRepositoryContent(modFolder.path!);
          modContent.tree?.forEach((element) {
            if (element.name == 'modmopet.yaml') {
              debugPrint('file found');
              String? modConfigContent = element.content;
              debugPrint(element.size.toString());
              if (modConfigContent != null) {
                debugPrint(modConfigContent);
                YamlDocument? modConfigYaml =
                    loadYamlDocument(modConfigContent);
                debugPrint(modConfigYaml.toString());
              }
              mods.add(Mod(id: 0, title: modFolder.name!, version: '1.0'));
            }
          });
        },
      );
    }

What I get: element.content is always NULL while filename and other values are filled correctly.

What I expect: The content of the file

github-actions[bot] commented 1 year ago

👋 Thanks for reporting! @robrbecker will take a look.

robrbecker commented 1 year ago

Ok, I figured out what's going on. When you call something like this var contents = await github.repositories.getContents(slug, path); If the path is a directory, you'll essentially get a file listing. For performance reasons the listing doesn't get all the contents for all the files in the listing. If the path is directly to a file, you'll get the file contents.

So in your loop once you find a filename you are interested in, if you do another call to get Contents with the full path to the file you should get the contents.

89pleasure commented 1 year ago

thanks for clarifying. 👍