From f53aa489fd9e92d940b1e2efd429b5ee58900473 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Tue, 19 Sep 2023 16:30:07 -0300 Subject: [PATCH] Preparing first version release --- .github/workflows/CI.yml | 7 ++----- Project.toml | 2 +- src/api.jl | 16 +++------------- src/context.jl | 7 +++++++ test/runtests.jl | 10 +++++++--- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 85cd107..15afd48 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -19,14 +19,10 @@ jobs: fail-fast: false matrix: version: - - '1.6' - - '1.7' - - '1.8' - - '1.9' + - '1' - 'nightly' os: - ubuntu-latest - - windows-latest arch: - x64 steps: @@ -41,6 +37,7 @@ jobs: env: SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }} + SLACK_USER: ${{ secrets.SLACK_USER }} - uses: julia-actions/julia-processcoverage@v1 - uses: codecov/codecov-action@v3 with: diff --git a/Project.toml b/Project.toml index 738a2d5..9584e1b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "SlackAPI" uuid = "45996516-d782-4985-8a4d-8a8f0336c9da" -version = "0.1.2" +version = "0.1.0" [deps] HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" diff --git a/src/api.jl b/src/api.jl index 31e81ab..d2c7c07 100644 --- a/src/api.jl +++ b/src/api.jl @@ -7,25 +7,15 @@ function channel_message( channel::AbstractString, text::AbstractString, ) - header = [ - "Content-Type" => "application/json;charset=utf-8", - "Authorization" => "Bearer $(context.token)", - ] - body = JSON.json(Dict("text" => text, "channel" => channel)) - return HTTP.post("https://slack.com/api/chat.postMessage", header, body) + return HTTP.post("https://slack.com/api/chat.postMessage", header(context), body) end function is_active(context::SlackContext, user::AbstractString) - header = [ - "Content-Type" => "application/json;charset=utf-8", - "Authorization" => "Bearer $(context.token)", - ] - - query = ["user" => user] + query = Dict("user" => user) - response = HTTP.get("https://slack.com/api/users.info", header, query) + response = HTTP.get("https://slack.com/api/users.info", header(context), query = query) @assert response.status == 200 diff --git a/src/context.jl b/src/context.jl index 704a4e3..2578a69 100644 --- a/src/context.jl +++ b/src/context.jl @@ -6,3 +6,10 @@ struct SlackContext return new(token) end end + +function header(context::SlackContext) + return [ + "Content-Type" => "application/json;charset=utf-8", + "Authorization" => "Bearer $(context.token)", + ] +end diff --git a/test/runtests.jl b/test/runtests.jl index bcaa673..a2a2101 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -13,18 +13,22 @@ function testall() token = ENV["SLACK_TOKEN"] channel = ENV["SLACK_CHANNEL"] + user = ENV["SLACK_USER"] @assert !isempty(token) @assert !isempty(channel) + @assert !isempty(user) context = SlackContext(token) response = SlackAPI.channel_message(context, channel, "testing...") - @assert response.status == 200 + @test response.status == 200 - @assert SlackAPI.mention("XXXX") == "<@XXXX>" + @test SlackAPI.mention("XXXX") == "<@XXXX>" - # @assert SlackAPI.is_active(context, user) + @test SlackAPI.is_active(context, user) == true + + @test SlackAPI.is_active(context, "U1234") == false end testall()