Masamune Model GitHub
[GitHub](https://github.com/mathrunet) | [YouTube](https://www.youtube.com/c/mathrunetchannel) | [Packages](https://pub.flutter-io.cn/publishers/mathru.net/packages) | [X](https://x.com/mathru) | [LinkedIn](https://www.linkedin.com/in/mathrunet/) | [mathru.net](https://mathru.net)
Masamune Model GitHub
Usage
Installation
- Add the package to your project.
flutter pub add masamune_model_github
Setup
- 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- RepositoriesGithubIssueModel- IssuesGithubPullRequestModel- Pull requestsGithubUserModel- UsersGithubOrganizationModel- OrganizationsGithubCommitModel- CommitsGithubBranchModel- BranchesGithubContentModel- Repository contentsGithubLabelModel- LabelsGithubMilestoneModel- MilestonesGithubProjectModel- Projects
Load GitHub Data
- 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 repositoriespublic_repo- Access public repositoriesread:org- Read org and team membershipuser- 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!
Libraries
- masamune_model_github
- Masamune plugin package that includes a model adapter to retrieve data from Github.
- models/github_actions
- models/github_actions_job
- models/github_actions_log
- models/github_branch
- models/github_commit
- models/github_compare
- models/github_content
- models/github_copilot_session
- models/github_copilot_session_log
- models/github_issue
- models/github_issue_timeline
- models/github_label
- models/github_license
- models/github_milestone
- models/github_organization
- models/github_project
- models/github_pull_request
- models/github_pull_request_head
- models/github_pull_request_timeline
- models/github_reaction
- models/github_repository
- models/github_repository_permission
- models/github_user