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

Wrap changelog query into class like GetChangelogBuildRequest. #2157

Closed
andy840119 opened this issue Dec 17, 2023 · 3 comments
Closed

Wrap changelog query into class like GetChangelogBuildRequest. #2157

andy840119 opened this issue Dec 17, 2023 · 3 comments
Labels
code quality Improve code quality.
Milestone

Comments

@andy840119
Copy link
Member

return initialFetchTask = Task.Run(async () =>
{
var tcs = new TaskCompletionSource<bool>();
var client = new GitHubClient(new ProductHeaderValue(organizationName));
try
{
var reposAscending = await client.Repository.Content.GetAllContentsByRef(organizationName, projectName, "content/changelog", branchName).ConfigureAwait(false);
if (reposAscending.Any())
{
builds.Clear();
builds.AddRange(reposAscending.Reverse().Where(x => x.Type == ContentType.Dir).Select(x => new APIChangelogBuild(organizationName, projectName, branchName)
{
RootUrl = x.HtmlUrl,
Path = x.Path,
DisplayVersion = x.Name,
PublishedAt = getPublishDateFromName(x.Name),
}));
foreach (var build in builds)
{
build.Versions.Previous = builds.GetPrevious(build);
build.Versions.Next = builds.GetNext(build);
}
tcs.SetResult(true);
}
else
{
tcs.SetResult(false);
}
}
catch (RateLimitExceededException)
{
// todo: maybe show something?
}
catch (Exception)
{
// todo: maybe show something?
}
await tcs.Task.ConfigureAwait(false);
});
static DateTimeOffset getPublishDateFromName(string name)
{
var regex = new Regex("(?<year>[-0-9]+).(?<month>[-0-9]{2})(?<day>[-0-9]{2})");
var result = regex.Match(name);
if (!result.Success)
return DateTimeOffset.MaxValue;
int year = result.GetGroupValue<int>("year");
int month = result.GetGroupValue<int>("month");
int day = result.GetGroupValue<int>("day");
return new DateTimeOffset(new DateTime(year, month, day));
}

Like in here, we did the logic for get the list of changelog build, paste the data and made some calculations
Maybe should make something like GetChangelogBuildRequest(might not just inherit the APIRequest because api is query from github, not osu!)

@andy840119 andy840119 added the code quality Improve code quality. label Dec 17, 2023
@andy840119
Copy link
Member Author

andy840119 commented Dec 17, 2023

Also, note that those classes in osu.game:

  • APIChangelogIndex : has list of channel and changelog metadata.
  • APIChangelogBuild : it's just a single changelog.
  • APINewsSidebar : it's an apo for able to get the list of post metadata and years.
  • APIWikiPage : has the full content in the wiki page (include markdown text).
  • WikiMainPage: 裡面有一些科技與狠活,會把 https://osu.ppy.sh/api/v2/wiki/en/Main_Page 上面的文字複製下來後,用 html 解析後排本。

image
And note that APIChangelogBuild in the APIChangelogIndex might not have content, or just little bit of content(for preview purpose).

Maybe should create similar info like:

  • APIChangelogSidebar or APIChangelogIndex : should be able to get list of change logs and years.
  • APIChangelogInfo: only contains the metadata (e.g. build version, display text, link)
  • APIChangelogBuild: contains the markdown content, previous build and next build(maybe with type APIChangelogInfo).

@andy840119
Copy link
Member Author

Also, not very sure will github provide the api that can get small content from the list of files:

But seems content property only exist only if select single of file:

gh api /repos/karaoke-dev/karaoke-dev.github.io/contents/content/changelog/2023.1212/index.md

will return:

{
  "name": "index.md",
  "path": "content/changelog/2023.1212/index.md",
  "sha": "791137b5ec2afcb43fb370de70a94be034207edc",
  "size": 362,
  "url": "https://api.github.com/repos/karaoke-dev/karaoke-dev.github.io/contents/content/changelog/2023.1212/index.md?ref=master",
  "html_url": "https://github.com/karaoke-dev/karaoke-dev.github.io/blob/master/content/changelog/2023.1212/index.md",
  "git_url": "https://api.github.com/repos/karaoke-dev/karaoke-dev.github.io/git/blobs/791137b5ec2afcb43fb370de70a94be034207edc",
  "download_url": "https://raw.githubusercontent.com/karaoke-dev/karaoke-dev.github.io/master/content/changelog/2023.1212/index.md",
  "type": "file",
  "content": "LS0tCnRpdGxlOiAiMjAyMy4xMjEyIgpkYXRlOiAyMDIzLTEyLTEyCi0tLQoK\nIyMgQWNoaWV2ZW1lbnQKCi0gVXNlIGNsb3VkZmxhcmUgYXMgQ0ROIGZvciB0\naGlzIGRvbWFpbi4gTmV4dCBzdGVwIGlzIHdhaXRpbmcgZm9yIGNsb3VkZmxh\ncmUgdG8gYWNjZXB0IHRoZSBkb21haW4uCi0gU3RpbGwgYnVzeWluZyBvbiBt\neSBqb2IgO1xfOwotIFdhaXRpbmcgZm9yIG15IHZhY2F0aW9uIHRyaXAuCi0g\nTlVuaXQgdXBncmFkZSB0byA0LjAgYW5kIGhhdmUgbG90cyBvZiBicmVha2lu\nZyBjaGFuZ2UgO1xfOwoKIyMgQ29kZSBxdWFsaXR5CgotIFVwZGF0ZSBwYWNr\nYWdlIHRvIHRoZSBsYXRlc3QuIFtrYXJhb2tlXSgjMjE1MkBhbmR5ODQwMTE5\nKQo=\n",
  "encoding": "base64",
  "_links": {
    "self": "https://api.github.com/repos/karaoke-dev/karaoke-dev.github.io/contents/content/changelog/2023.1212/index.md?ref=master",
    "git": "https://api.github.com/repos/karaoke-dev/karaoke-dev.github.io/git/blobs/791137b5ec2afcb43fb370de70a94be034207edc",
    "html": "https://github.com/karaoke-dev/karaoke-dev.github.io/blob/master/content/changelog/2023.1212/index.md"
  }
}

otherwise:

gh api /repos/karaoke-dev/karaoke-dev.github.io/contents/content/changelog/2023.1212

it will return:

[
  {
    "name": "index.md",
    "path": "content/changelog/2023.1212/index.md",
    "sha": "791137b5ec2afcb43fb370de70a94be034207edc",
    "size": 362,
    "url": "https://api.github.com/repos/karaoke-dev/karaoke-dev.github.io/contents/content/changelog/2023.1212/index.md?ref=master",
    "html_url": "https://github.com/karaoke-dev/karaoke-dev.github.io/blob/master/content/changelog/2023.1212/index.md",
    "git_url": "https://api.github.com/repos/karaoke-dev/karaoke-dev.github.io/git/blobs/791137b5ec2afcb43fb370de70a94be034207edc",
    "download_url": "https://raw.githubusercontent.com/karaoke-dev/karaoke-dev.github.io/master/content/changelog/2023.1212/index.md",
    "type": "file",
    "_links": {
      "self": "https://api.github.com/repos/karaoke-dev/karaoke-dev.github.io/contents/content/changelog/2023.1212/index.md?ref=master",
      "git": "https://api.github.com/repos/karaoke-dev/karaoke-dev.github.io/git/blobs/791137b5ec2afcb43fb370de70a94be034207edc",
      "html": "https://github.com/karaoke-dev/karaoke-dev.github.io/blob/master/content/changelog/2023.1212/index.md"
    }
  }
]

@andy840119
Copy link
Member Author

Implemented.

@andy840119 andy840119 added this to the 2024.0224 milestone Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Improve code quality.
Projects
None yet
Development

No branches or pull requests

1 participant