Move types to types.hpp.
This commit is contained in:
parent
16821fd90c
commit
96b8967f24
11
src/cgi.hpp
11
src/cgi.hpp
|
@ -17,6 +17,8 @@
|
|||
#ifndef FEDIBLOCK_BACKEND_CGI_HPP
|
||||
#define FEDIBLOCK_BACKEND_CGI_HPP
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
@ -28,15 +30,6 @@ using std::string;
|
|||
using std::string_view;
|
||||
using std::vector;
|
||||
|
||||
struct entry_type
|
||||
{
|
||||
string instance;
|
||||
vector<string> tags;
|
||||
vector<string> receipts;
|
||||
string description;
|
||||
string screenshot_filepath;
|
||||
};
|
||||
|
||||
// Read form data from QUERY_STRING or stdin and return it as an object.
|
||||
[[nodiscard]] entry_type parse_formdata();
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ void create_branch()
|
|||
check(git_repository_set_head(_repo, ref_name.c_str()));
|
||||
}
|
||||
|
||||
void commit(const cgi::entry_type &entry)
|
||||
void commit(const entry_type &entry)
|
||||
{
|
||||
// Write files.
|
||||
const string basename{files::get_tmpdir() / "repo" / get_branch_name()};
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#ifndef FEDIBLOCK_BACKEND_GIT_HPP
|
||||
#define FEDIBLOCK_BACKEND_GIT_HPP
|
||||
|
||||
#include "cgi.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
#include <git2.h>
|
||||
|
||||
|
@ -45,7 +45,7 @@ void clone();
|
|||
void create_branch();
|
||||
|
||||
// Make a new commit.
|
||||
void commit(const cgi::entry_type &entry);
|
||||
void commit(const entry_type &entry);
|
||||
|
||||
// Push the new commit.
|
||||
void push();
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
#include "gitea.hpp"
|
||||
|
||||
#include "cgi.hpp"
|
||||
#include "files.hpp"
|
||||
#include "json.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
@ -143,7 +143,7 @@ string api_request(const http_method method, const string_view path,
|
|||
return _curl_buffer_body;
|
||||
}
|
||||
|
||||
void pull_request(const string_view branch, const cgi::entry_type &entry)
|
||||
void pull_request(const string_view branch, const entry_type &entry)
|
||||
{
|
||||
api_request(http_method::POST,
|
||||
(string("/api/v1/repos/") += _repo_name) += "/pulls",
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#ifndef FEDIBLOCK_BACKEND_GITEA_HPP
|
||||
#define FEDIBLOCK_BACKEND_GITEA_HPP
|
||||
|
||||
#include "cgi.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
@ -30,12 +30,6 @@ using std::string;
|
|||
using std::string_view;
|
||||
using std::uint64_t;
|
||||
|
||||
enum class http_method
|
||||
{
|
||||
GET,
|
||||
POST
|
||||
};
|
||||
|
||||
// Initialize the curl connection handle.
|
||||
void init();
|
||||
|
||||
|
@ -49,7 +43,7 @@ size_t writer_body(char *data, size_t size, size_t nmemb);
|
|||
string api_request(http_method method, string_view path, string_view body);
|
||||
|
||||
// Make a pull request.
|
||||
void pull_request(string_view branch, const cgi::entry_type &entry);
|
||||
void pull_request(string_view branch, const entry_type &entry);
|
||||
|
||||
// Get number of last pull request.
|
||||
[[nodiscard]] uint64_t get_last_pr_number();
|
||||
|
|
|
@ -16,13 +16,14 @@
|
|||
|
||||
#include "json.hpp"
|
||||
#include "fs-compat.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace FediBlock::json
|
||||
{
|
||||
|
||||
string to_json(const cgi::entry_type &entry)
|
||||
string to_json(const entry_type &entry)
|
||||
{
|
||||
const string filename{fs::path(entry.screenshot_filepath).filename()};
|
||||
const nlohmann::json json{{"instance", entry.instance},
|
||||
|
@ -33,7 +34,7 @@ string to_json(const cgi::entry_type &entry)
|
|||
return json.dump(4);
|
||||
}
|
||||
|
||||
string pull_request_body(string_view branch, const cgi::entry_type &entry)
|
||||
string pull_request_body(string_view branch, const entry_type &entry)
|
||||
{
|
||||
const nlohmann::json json{{"base", "main"},
|
||||
{"head", branch.data()},
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#ifndef FEDIBLOCK_BACKEND_JSON_HPP
|
||||
#define FEDIBLOCK_BACKEND_JSON_HPP
|
||||
|
||||
#include "cgi.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
@ -29,11 +29,11 @@ using std::string;
|
|||
using std::string_view;
|
||||
|
||||
// Convert an entry_type into a JSON string.
|
||||
[[nodiscard]] string to_json(const cgi::entry_type &entry);
|
||||
[[nodiscard]] string to_json(const entry_type &entry);
|
||||
|
||||
// Return the body for a pull request.
|
||||
[[nodiscard]] string pull_request_body(string_view branch,
|
||||
const cgi::entry_type &entry);
|
||||
const entry_type &entry);
|
||||
|
||||
} // namespace FediBlock::json
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "git.hpp"
|
||||
#include "gitea.hpp"
|
||||
#include "json.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
#include <git2/global.h>
|
||||
|
||||
|
@ -43,7 +44,7 @@ int main()
|
|||
|
||||
try
|
||||
{
|
||||
const cgi::entry_type entry{cgi::parse_formdata()};
|
||||
const entry_type entry{cgi::parse_formdata()};
|
||||
|
||||
git::clone();
|
||||
git::create_branch();
|
||||
|
|
46
src/types.hpp
Normal file
46
src/types.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/* This file is part of FediBlock-backend.
|
||||
* Copyright © 2020 tastytea <tastytea@tastytea.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FEDIBLOCK_BACKEND_TYPES_HPP
|
||||
#define FEDIBLOCK_BACKEND_TYPES_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace FediBlock
|
||||
{
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
struct entry_type
|
||||
{
|
||||
string instance;
|
||||
vector<string> tags;
|
||||
vector<string> receipts;
|
||||
string description;
|
||||
string screenshot_filepath;
|
||||
};
|
||||
|
||||
enum class http_method
|
||||
{
|
||||
GET,
|
||||
POST
|
||||
};
|
||||
|
||||
} // namespace FediBlock
|
||||
|
||||
#endif // FEDIBLOCK_BACKEND_TYPES_HPP
|
Reference in New Issue
Block a user