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

Update to Bot API 7.7 #80

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![.NET Core](https://github.com/Dolfik1/Funogram/workflows/.NET/badge.svg)
[![NuGet](https://img.shields.io/nuget/v/Funogram.svg)](https://www.nuget.org/packages/Funogram/)
[![NuGet](https://img.shields.io/nuget/v/Funogram.Telegram.svg)](https://www.nuget.org/packages/Funogram.Telegram/)
[![NuGet](https://img.shields.io/badge/Bot%20API-7.3-blue?logo=telegram)](https://www.nuget.org/packages/Funogram.Telegram/)
[![NuGet](https://img.shields.io/badge/Bot%20API-7.7-blue?logo=telegram)](https://www.nuget.org/packages/Funogram.Telegram/)

<img src="https://github.com/Dolfik1/Funogram/raw/master/docs/files/img/logo.png" alt="Funogram Logo" width="200" align="right" />

Expand Down
8 changes: 8 additions & 0 deletions src/Funogram.Generator/Constants.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module Funogram.Generator.Constants
[<Literal>]
let ApiUri = "https://core.telegram.org/bots/api"


[<Literal>]
let RootDir = "../../"

[<Literal>]
let CodeOutputDir = "../Funogram.Telegram/"

Expand All @@ -19,5 +23,9 @@ let MethodsFileName = "RequestsTypes.fs"
[<Literal>]
let TypesFileName = "Types.fs"

[<Literal>]
let BuildPropsFileName = "Directory.Build.props"

[<Literal>]
let ReadmeFileName = "README.md"

1 change: 1 addition & 0 deletions src/Funogram.Generator/Funogram.Generator.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<Compile Include="Types\Types.fs" />
<Compile Include="Types\TypesParser.fs" />
<Compile Include="Types\TypesGenerator.fs" />
<Compile Include="VersionParser.fs" />
<Compile Include="Program.fs" />
<Content Include="RemapTypes.json" />
<Content Include="RemapMethods.json" />
Expand Down
5 changes: 5 additions & 0 deletions src/Funogram.Generator/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ let processAsync (args: CliArguments list) =

|> MethodsGenerator.mkGenerator (Path.Combine(Constants.CodeOutputDir, Constants.MethodsFileName))
|> MethodsGenerator.generate

VersionParser.mkParser html
|> VersionParser.withBuildPropsPath (Path.Combine(Constants.CodeOutputDir, Constants.BuildPropsFileName))
|> VersionParser.withReadmePath (Path.Combine(Constants.RootDir, Constants.ReadmeFileName))
|> VersionParser.parseAndWrite
}

[<EntryPoint>]
Expand Down
80 changes: 80 additions & 0 deletions src/Funogram.Generator/VersionParser.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[<Microsoft.FSharp.Core.RequireQualifiedAccess>]
module Funogram.Generator.VersionParser

open System
open System.IO
open System.Xml
open System.Xml.Linq
open FSharp.Data

type ParseConfig =
{
Document: HtmlDocument
BuildPropsPath: string option
ReadmePath: string option
}

let mkParser (html: HtmlDocument) =
{
Document = html
BuildPropsPath = None
ReadmePath = None
}

let withBuildPropsPath path config =
{ config with BuildPropsPath = Some path }

let withReadmePath path config =
{ config with ReadmePath = Some path }

let private parseVersion (text: string) =
try
Some (text.Split('.') |> Array.map Int32.Parse)
with
| _ -> None

let private updateReadme (apiVersion: int[]) (path: string) =
let version = apiVersion |> Seq.map string |> String.concat "."
let lines = File.ReadAllLines(path)
match lines |> Seq.tryFindIndex (_.StartsWith("[![NuGet](https://img.shields.io/badge/Bot")) with
| Some badgeIndex ->
lines[badgeIndex] <- $"[![NuGet](https://img.shields.io/badge/Bot%%20API-{version}-blue?logo=telegram)](https://www.nuget.org/packages/Funogram.Telegram/)"
File.WriteAllLines(path, lines)
| None ->
printfn "Unable to find line with version badge."

let parseAndWrite (config: ParseConfig) =
let content = config.Document.CssSelect("#dev_page_content > p > strong") |> Seq.head
let version = content.InnerText() |> String.filter (fun x -> x = '.' || Char.IsDigit(x))

match parseVersion version with
| Some newApiVersion ->
match config.BuildPropsPath with
| Some buildPropsPath ->
use fs = File.Open(buildPropsPath, FileMode.Open)
let doc = XDocument.Load(fs)
fs.Close()
let versionNode = doc.Root.Element("PropertyGroup").Element("Version")
match parseVersion versionNode.Value with
| Some currentVersion ->
let newVersion =
if currentVersion[0] <> newApiVersion[0] || currentVersion[1] <> newApiVersion[1] then
let zeros = Array.zeroCreate (4 - newApiVersion.Length)
Array.append newApiVersion zeros |> Seq.map string |> String.concat "."
else
currentVersion[currentVersion.Length - 1] <- currentVersion[currentVersion.Length - 1] + 1
currentVersion |> Seq.map string |> String.concat "."
versionNode.Value <- newVersion
printfn $"Updating {buildPropsPath} with new version {newVersion}"
doc.Save(buildPropsPath)
config.ReadmePath |> Option.iter (updateReadme newApiVersion)
| None -> ()
| None ->
printfn "WARN: Version parsed, but not used, because Build.Props path is not set!"
()
| None ->
printfn $"WARN: Unable to parse API version: {version} (from element with content: {content})"




Loading
Loading