Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RepositoryContent.content is always null #369

Closed
89pleasure opened this issue May 20, 2023 · 3 comments
Closed

RepositoryContent.content is always null #369

89pleasure opened this issue May 20, 2023 · 3 comments

Comments

@89pleasure
Copy link

89pleasure commented May 20, 2023

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
Copy link

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

@robrbecker
Copy link
Member

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
Copy link
Author

thanks for clarifying. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants