masamune_model_github 3.6.3 copy "masamune_model_github: ^3.6.3" to clipboard
masamune_model_github: ^3.6.3 copied to clipboard

Masamune plugin package that includes a model adapter to retrieve data from Github.

Masamune logo

Masamune Model GitHub

Follow on GitHub Follow on X Follow on YouTube Maintained with Melos

GitHub Sponsor


[GitHub] | [YouTube] | [Packages] | [X] | [LinkedIn] | [mathru.net]


Masamune Model GitHub #

Usage #

Installation #

  1. Add the package to your project.
flutter pub add masamune_model_github

Setup #

  1. Create a GitHub API token and configure the adapter. The token should have the scopes required for the data you plan to access or mutate.
// lib/main.dart

import 'package:masamune_model_github/masamune_model_github.dart';

final githubAdapter = GithubModelAdapter(
  onRetrieveToken: () async {
    // Return your GitHub personal access token
    // Store securely using environment variables or secret storage
    return String.fromEnvironment("GITHUB_TOKEN");
  },
);

final masamuneAdapters = <MasamuneAdapter>[
  GithubModelMasamuneAdapter(
    modelAdapter: githubAdapter,
    appRef: appRef,
  ),
];

void main() {
  runMasamuneApp(
    appRef: appRef,
    modelAdapter: githubAdapter,
    masamuneAdapters: masamuneAdapters,
    (appRef, _) => MasamuneApp(
      appRef: appRef,
      home: HomePage(),
    ),
  );
}

Available Models #

The package provides pre-built models for GitHub API entities:

  • GithubRepositoryModel - Repositories
  • GithubIssueModel - Issues
  • GithubPullRequestModel - Pull requests
  • GithubUserModel - Users
  • GithubOrganizationModel - Organizations
  • GithubCommitModel - Commits
  • GithubBranchModel - Branches
  • GithubContentModel - Repository contents
  • GithubLabelModel - Labels
  • GithubMilestoneModel - Milestones
  • GithubProjectModel - Projects

Load GitHub Data #

  1. Load GitHub resources using the generated models:
class RepositoriesPage extends PageScopedWidget {
  @override
  Widget build(BuildContext context, PageRef ref) {
    // Load repositories for an organization
    final repos = ref.app.model(
      GithubRepositoryModel.collection(organizationId: "flutter"),
    )..load();

    return ListView.builder(
      itemCount: repos.length,
      itemBuilder: (context, index) {
        final repo = repos[index].value;
        return ListTile(
          title: Text(repo?.name ?? ''),
          subtitle: Text(repo?.description ?? ''),
          trailing: Text('⭐ ${repo?.stargazersCount ?? 0}'),
        );
      },
    );
  }
}

Load Issues and Pull Requests #

// Load issues for a repository
final issues = ref.app.model(
  GithubIssueModel.collection(
    organizationId: "flutter",
    repositoryId: "flutter",
  ),
)..load();

// Load pull requests
final pullRequests = ref.app.model(
  GithubPullRequestModel.collection(
    organizationId: "flutter",
    repositoryId: "flutter",
  ),
)..load();

Create/Update GitHub Resources #

// Create a new issue
final issueCollection = ref.app.model(
  GithubIssueModel.collection(
    organizationId: "myorg",
    repositoryId: "myrepo",
  ),
);

final newIssue = issueCollection.create();
await newIssue.save(
  GithubIssueModel(
    title: 'Bug Report',
    body: 'Description of the bug...',
    labels: ['bug', 'high-priority'],
  ),
);

GitHub Token Setup #

Create a Personal Access Token at GitHub Settings → Developer settings → Personal access tokens.

Required scopes depend on your use case:

  • repo - Full control of private repositories
  • public_repo - Access public repositories
  • read:org - Read org and team membership
  • user - Read user profile data

Store the token securely:

# Set as environment variable
export GITHUB_TOKEN="ghp_your_token_here"

# Or use --dart-define
flutter run --dart-define=GITHUB_TOKEN=ghp_your_token_here

GitHub Sponsors #

Sponsors are always welcome. Thank you for your support!

https://github.com/sponsors/mathrunet

0
likes
80
points
7
downloads

Publisher

verified publishermathru.net

Weekly Downloads

Masamune plugin package that includes a model adapter to retrieve data from Github.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

archive, flutter, freezed_annotation, github, json_annotation, katana, masamune, meta

More

Packages that depend on masamune_model_github