Skip to content
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
32 changes: 30 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
version: 2

jobs:
danger:
macos:
xcode: 10.2.0
steps:
- checkout
- run:
name: Set Ruby Version
command: echo "ruby-2.4" > ~/.ruby-version
- restore_cache:
key: 1-gems-{{ checksum "Gemfile.lock" }}
- run:
name: Install Ruby Dependencies
command: bundle check || bundle install
environment:
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
- save_cache:
key: 1-gems-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- run:
name: Danger
command: bundle exec danger
macos:
environment:
TEST_REPORTS: /tmp/test-results
Expand Down Expand Up @@ -51,5 +74,10 @@ workflows:
version: 2
tests:
jobs:
- linux
- macos
- danger
- linux:
requires:
- danger
- macos:
requires:
- danger
18 changes: 17 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@

identifier_name:
min_length: # only min_length
warning: 2
error: 2 # only error
excluded: # excluded via string array
- ok
- Name
- DEFAULT_MIME_TYPE
- sin_port
- no_sig_pipe

disabled_rules:
- line_length
- statement_position
- trailing_whitespace
- variable_name_min_length

excluded: # paths to ignore during linting. Takes precedence over `included`.
- LinuxMain.swift
- Tests/XCTestManifests.swift
- Package.swift
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file. Changes not

## Added
- A new `CHANGELOG.md` to keep track of changes in the project. ([#385](https://github.com/httpswift/swifter/pull/385)) by [@Vkt0r](https://github.com/Vkt0r)
- Added [Danger](https://danger.systems/ruby/) and Swiftlint to the project. ([#398](https://github.com/httpswift/swifter/pull/398)) by [@Vkt0r](https://github.com/Vkt0r)

## Fixed
- An issue in the `HttpRouter` causing issues to handle routes with overlapping in the tail. ([#379](https://github.com/httpswift/swifter/pull/359), [#382](https://github.com/httpswift/swifter/pull/382)) by [@Vkt0r](https://github.com/Vkt0r)
Expand Down
36 changes: 36 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# send a welcome message for the user
message "Hey, @#{github.pr_author} 👋."

# Just to let people know
warn("PR is classed as Work in Progress.") if github.pr_title.include? "[WIP]"

# Warn when there is a big PR
warn("Big PR") if git.lines_of_code > 500

# ensure there is a summary for a PR
fail "Please provide a summary in the Pull Request description." if github.pr_body.length < 5

# Changelog entries are required for changes to library files.
fail("Please include a CHANGELOG entry. You can find it at [CHANGELOG.md](https://github.com/httpswift/swifter/blob/stable/CHANGELOG.md).") unless git.modified_files.include?("CHANGELOG.md") || git.added_files.include?("CHANGELOG.md")

# Don't accept PR on master for now
fail "Please re-submit this PR to stable, you're trying to merge the PR on master." if github.branch_for_base == "master"

# If these are all empty something has gone wrong, better to raise it in a comment
if git.modified_files.empty? && git.added_files.empty? && git.deleted_files.empty?
fail "This PR has no changes at all, this is likely a developer issue."
end

# Run SwiftLint
swiftlint.config_file = '.swiftlint.yml'
swiftlint.lint_files

# Warn when new tests are added but the XCTestManifests wasn't updated to run on Linux
tests_added_or_modified = git.modified_files.grep(/XCode\/Tests/).empty? || git.added_files.grep(/XCode\/Tests/).empty?
xc_manifest_updated = !git.modified_files.grep(/XCode\/Tests\/XCTestManifests.swift/).empty?
if tests_added_or_modified && !xc_manifest_updated
warn("It seems like you've added new tests to the library. If that's the case, please update the [XCTestManifests.swift](https://github.com/httpswift/swifter/blob/stable/XCode/Tests/XCTestManifests.swift) file running in your terminal the command `swift test --generate-linuxmain`.")

# This is a temporary warning to remove the entry for the failed test until we solve the issue in Linux
warn("If you ran the command `swift test --generate-linuxmain` in your terminal, please remove the line `testCase(IOSafetyTests.__allTests__IOSafetyTests),` from `public func __allTests() -> [XCTestCaseEntry]` in the bottom of the file. For more reference see [#366](https://github.com/httpswift/swifter/issues/366).")
end
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem 'danger'
gem 'danger-swiftlint'
63 changes: 63 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
claide (1.0.2)
claide-plugins (0.9.2)
cork
nap
open4 (~> 1.3)
colored2 (3.1.2)
cork (0.3.0)
colored2 (~> 3.1)
danger (6.0.6)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
cork (~> 0.1)
faraday (~> 0.9)
faraday-http-cache (~> 1.0)
git (~> 1.5)
kramdown (~> 2.0)
kramdown-parser-gfm (~> 1.0)
no_proxy_fix
octokit (~> 4.7)
terminal-table (~> 1)
danger-swiftlint (0.20.1)
danger
rake (> 10)
thor (~> 0.19)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
faraday-http-cache (1.3.1)
faraday (~> 0.8)
git (1.5.0)
kramdown (2.1.0)
kramdown-parser-gfm (1.0.1)
kramdown (~> 2.0)
multipart-post (2.0.0)
nap (1.1.0)
no_proxy_fix (0.1.2)
octokit (4.14.0)
sawyer (~> 0.8.0, >= 0.5.3)
open4 (1.3.4)
public_suffix (3.0.3)
rake (12.3.2)
sawyer (0.8.1)
addressable (>= 2.3.5, < 2.6)
faraday (~> 0.8, < 1.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
thor (0.20.3)
unicode-display_width (1.5.0)

PLATFORMS
ruby

DEPENDENCIES
danger
danger-swiftlint

BUNDLED WITH
1.16.5
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let package = Package(
dependencies: [],

targets: [
.target(name: "Swifter", dependencies: [], path: "Sources"),
.target(name: "Swifter", dependencies: [], path: "XCode/Sources"),
.target(name: "Example", dependencies: ["Swifter"], path: "Example"),
.testTarget(name: "SwifterTests", dependencies: ["Swifter"], path: "XCode/Tests")
]
Expand Down
60 changes: 30 additions & 30 deletions Sources/DemoServer.swift → XCode/Sources/DemoServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation


// swiftlint:disable function_body_length
public func demoServer(_ publicDir: String) -> HttpServer {

print(publicDir)
Expand All @@ -32,17 +32,17 @@ public func demoServer(_ publicDir: String) -> HttpServer {

server["/magic"] = { .ok(.html("You asked for " + $0.path)) }

server["/test/:param1/:param2"] = { r in
server["/test/:param1/:param2"] = { request in
scopes {
html {
body {
h3 { inner = "Address: \(r.address ?? "unknown")" }
h3 { inner = "Url: \(r.path)" }
h3 { inner = "Method: \(r.method)" }
h3 { inner = "Address: \(request.address ?? "unknown")" }
h3 { inner = "Url: \(request.path)" }
h3 { inner = "Method: \(request.method)" }

h3 { inner = "Query:" }

table(r.queryParams) { param in
table(request.queryParams) { param in
tr {
td { inner = param.0 }
td { inner = param.1 }
Expand All @@ -51,7 +51,7 @@ public func demoServer(_ publicDir: String) -> HttpServer {

h3 { inner = "Headers:" }

table(r.headers) { header in
table(request.headers) { header in
tr {
td { inner = header.0 }
td { inner = header.1 }
Expand All @@ -60,15 +60,15 @@ public func demoServer(_ publicDir: String) -> HttpServer {

h3 { inner = "Route params:" }

table(r.params) { param in
table(request.params) { param in
tr {
td { inner = param.0 }
td { inner = param.1 }
}
}
}
}
}(r)
}(request)
}

server.GET["/upload"] = scopes {
Expand All @@ -92,9 +92,9 @@ public func demoServer(_ publicDir: String) -> HttpServer {
}
}

server.POST["/upload"] = { r in
server.POST["/upload"] = { request in
var response = ""
for multipart in r.parseMultiPartFormData() {
for multipart in request.parseMultiPartFormData() {
guard let name = multipart.name, let fileName = multipart.fileName else { continue }
response += "Name: \(name) File name: \(fileName) Size: \(multipart.body.count)<br>"
}
Expand Down Expand Up @@ -134,8 +134,8 @@ public func demoServer(_ publicDir: String) -> HttpServer {
}
}

server.POST["/login"] = { r in
let formFields = r.parseUrlencodedForm()
server.POST["/login"] = { request in
let formFields = request.parseUrlencodedForm()
return HttpResponse.ok(.html(formFields.map({ "\($0.0) = \($0.1)" }).joined(separator: "<br>")))
}

Expand All @@ -150,32 +150,32 @@ public func demoServer(_ publicDir: String) -> HttpServer {
}
}

server["/raw"] = { r in
server["/raw"] = { _ in
return HttpResponse.raw(200, "OK", ["XXX-Custom-Header": "value"], { try $0.write([UInt8]("test".utf8)) })
}

server["/redirect/permanently"] = { r in
server["/redirect/permanently"] = { _ in
return .movedPermanently("http://www.google.com")
}

server["/redirect/temporarily"] = { r in
server["/redirect/temporarily"] = { _ in
return .movedTemporarily("http://www.google.com")
}

server["/long"] = { r in
server["/long"] = { _ in
var longResponse = ""
for k in 0..<1000 { longResponse += "(\(k)),->" }
for index in 0..<1000 { longResponse += "(\(index)),->" }
return .ok(.html(longResponse))
}

server["/wildcard/*/test/*/:param"] = { r in
return .ok(.html(r.path))
server["/wildcard/*/test/*/:param"] = { request in
return .ok(.html(request.path))
}

server["/stream"] = { r in
return HttpResponse.raw(200, "OK", nil, { w in
for i in 0...100 {
try w.write([UInt8]("[chunk \(i)]".utf8))
server["/stream"] = { _ in
return HttpResponse.raw(200, "OK", nil, { writer in
for index in 0...100 {
try writer.write([UInt8]("[chunk \(index)]".utf8))
}
})
}
Expand All @@ -184,20 +184,20 @@ public func demoServer(_ publicDir: String) -> HttpServer {
session.writeText(text)
}, binary: { (session, binary) in
session.writeBinary(binary)
}, pong: { (session, pong) in
}, pong: { (_, _) in
// Got a pong frame
}, connected: { (session) in
}, connected: { _ in
// New client connected
}, disconnected: { (session) in
}, disconnected: { _ in
// Client disconnected
})

server.notFoundHandler = { r in
server.notFoundHandler = { _ in
return .movedPermanently("https://github.com/404")
}

server.middleware.append { r in
print("Middleware: \(r.address ?? "unknown address") -> \(r.method) -> \(r.path)")
server.middleware.append { request in
print("Middleware: \(request.address ?? "unknown address") -> \(request.method) -> \(request.path)")
return nil
}

Expand Down
File renamed without changes.
Loading