SlHelpers
Loading...
Searching...
No Matches
Maintainers.h
1// SPDX-License-Identifier: GPL-2.0-only
2
3#pragma once
4
5#include <filesystem>
6#include <optional>
7#include <set>
8#include <string>
9#include <vector>
10
11#include "Stanza.h"
12
13namespace SlKernCVS {
14
20class Maintainers {
21public:
23 using MaintainersType = std::vector<Stanza>;
24
35 static std::optional<Maintainers> load(const std::filesystem::path &SUSE,
36 const std::filesystem::path &linuxRepo,
37 const std::string &origin,
38 const Stanza::TranslateEmail &translateEmail) {
39 Maintainers m;
40
41 if (!m.loadSUSE(SUSE, translateEmail))
42 return std::nullopt;
43 if (!linuxRepo.empty() && !m.loadUpstream(linuxRepo, origin, translateEmail))
44 return std::nullopt;
45
46 return m;
47 }
48
54 const Stanza *findBestMatch(const std::set<std::filesystem::path> &paths) const {
55 return findBestMatchInMaintainers(m_maintainers, paths);
56 }
57
62 const Stanza *findBestMatchUpstream(const std::set<std::filesystem::path> &paths) const {
63 return findBestMatchInMaintainers(m_upstream_maintainers, paths);
64 }
65
70 const MaintainersType &maintainers() const { return m_maintainers; }
75 const MaintainersType &upstream_maintainers() const { return m_upstream_maintainers; }
80 const std::set<std::string> &suse_users() const { return m_suse_users; }
81private:
82 Maintainers() {}
83
84 bool loadSUSE(const std::filesystem::path &filename,
85 const Stanza::TranslateEmail &translateEmail);
86 bool loadUpstream(const std::filesystem::path &lsource, const std::string &origin,
87 const Stanza::TranslateEmail &translateEmail);
88
89 static const Stanza *findBestMatchInMaintainers(const MaintainersType &sl,
90 const std::set<std::filesystem::path> &paths);
91
92 MaintainersType m_maintainers;
93 MaintainersType m_upstream_maintainers;
94 std::set<std::string> m_suse_users;
95};
96
97}
Loads and holds information from both Linux and SUSE MAINTAINERS files.
Definition Maintainers.h:20
const MaintainersType & upstream_maintainers() const
Get all parsed Linux maintainers.
Definition Maintainers.h:75
const Stanza * findBestMatch(const std::set< std::filesystem::path > &paths) const
Find the best matched maintainer from the SUSE's MAINTAINERS file.
Definition Maintainers.h:54
const std::set< std::string > & suse_users() const
Get all met SUSE users.
Definition Maintainers.h:80
const MaintainersType & maintainers() const
Get all parsed SUSE maintainers.
Definition Maintainers.h:70
const Stanza * findBestMatchUpstream(const std::set< std::filesystem::path > &paths) const
Find the best matched maintainer from the Linux's MAINTAINERS file.
Definition Maintainers.h:62
static std::optional< Maintainers > load(const std::filesystem::path &SUSE, const std::filesystem::path &linuxRepo, const std::string &origin, const Stanza::TranslateEmail &translateEmail)
Load maintainers info.
Definition Maintainers.h:35
std::vector< Stanza > MaintainersType
Maintainers are a list of stanzas.
Definition Maintainers.h:23
Stanza (a subsystem) from MAINTAINERS file.
Definition Stanza.h:23
std::function< std::string(std::string_view sv)> TranslateEmail
Callback to translate an e-mail.
Definition Stanza.h:26