• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eiriksm / cosy-composer / 13715678822

07 Mar 2025 07:13AM UTC coverage: 86.43% (+0.2%) from 86.28%
13715678822

push

github

web-flow
Refactor individual update (#398)

* Refactor individual update

* Code style

* new.files

* Update GitCommandsTrait.php

* Update GitCommandsTrait.php

* Update PrParamsCreator.php

608 of 643 new or added lines in 14 files covered. (94.56%)

3 existing lines in 1 file now uncovered.

1777 of 2056 relevant lines covered (86.43%)

43.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/src/PrParamsCreator.php
1
<?php
2

3
namespace eiriksm\CosyComposer;
4

5
use eiriksm\ViolinistMessages\ViolinistMessages;
6
use eiriksm\ViolinistMessages\ViolinistUpdate;
7
use Psr\Log\LoggerAwareTrait;
8
use Violinist\Config\Config;
9
use Violinist\ProjectData\ProjectData;
10
use Violinist\Slug\Slug;
11

12
class PrParamsCreator
13
{
14
    use AssigneesAllowedTrait;
15
    use LoggerAwareTrait;
16

17
    /**
18
     * @var ViolinistMessages
19
     */
20
    private $messageFactory;
21

22
    /**
23
     * @var ProjectData|null
24
     */
25
    private $projectData;
26

27
    public function __construct(ViolinistMessages $messageFactory, ?ProjectData $projectData = null)
28
    {
29
        $this->messageFactory = $messageFactory;
116✔
30
        $this->projectData = $projectData;
116✔
31
    }
32

33
    public function setAssigneesAllowed(bool $assigneesAllowed)
34
    {
35
        $this->assigneesAllowed = $assigneesAllowed;
92✔
36
    }
37

38
    /**
39
     * Helper to create body.
40
     */
41
    public function createBody($item, $post_update_data, $changelog = null, $security_update = false, array $update_list = [], $changed_files = [], $release_notes_for_package = [])
42
    {
43
        $update = new ViolinistUpdate();
112✔
44
        $update->setName($item->name);
112✔
45
        $update->setCurrentVersion($item->version);
112✔
46
        $update->setNewVersion($post_update_data->version);
112✔
47
        $update->setSecurityUpdate($security_update);
112✔
48
        if ($changelog) {
112✔
49
            /** @var \Violinist\GitLogFormat\ChangeLogData $changelog */
NEW
50
            $update->setChangelog($changelog->getAsMarkdown());
×
51
        }
52
        if ($this->projectData && $this->projectData->getCustomPrMessage()) {
112✔
53
            $update->setCustomMessage($this->projectData->getCustomPrMessage());
1✔
54
        }
55
        $update->setUpdatedList($update_list);
112✔
56
        if ($changed_files) {
112✔
NEW
57
            $update->setChangedFiles($changed_files);
×
58
        }
59
        if ($release_notes_for_package) {
112✔
NEW
60
            $update->setPackageReleaseNotes($release_notes_for_package);
×
61
        }
62
        return $this->messageFactory->getPullRequestBody($update);
112✔
63
    }
64

65
    /**
66
     * Creates a title for a PR.
67
     *
68
     * @param \stdClass $item
69
     *   The item in question.
70
     *
71
     * @return string
72
     *   A string ready to use.
73
     */
74
    public function createTitle($item, $post_update_data, $security_update = false)
75
    {
76
        $update = new ViolinistUpdate();
96✔
77
        $update->setName($item->name);
96✔
78
        $update->setCurrentVersion($item->version);
96✔
79
        $update->setNewVersion($post_update_data->version);
96✔
80
        $update->setSecurityUpdate($security_update);
96✔
81
        if ($item->version === $post_update_data->version) {
96✔
82
            // I guess we are updating the dependencies? We are surely not updating from one version to the same.
83
            return sprintf('Update dependencies of %s', $item->name);
4✔
84
        }
85
        return trim($this->messageFactory->getPullRequestTitle($update));
92✔
86
    }
87

88
    public function getPrParams($fork_user, bool $is_private, Slug $slug, $branch_name, $body, $title, $default_branch, Config $config)
89
    {
90
        $head = $fork_user . ':' . $branch_name;
112✔
91
        if ($is_private) {
112✔
92
            $head = $branch_name;
111✔
93
        }
94
        if ($slug->getProvider() === 'bitbucket.org') {
112✔
95
            // Currently does not support having the collapsible section thing.
96
            // @todo: Revisit from time to time?
97
            // @todo: Make sure we replace the correct one. What if the changelog has this in it?
98
            $body = str_replace([
2✔
99
                '<details>',
2✔
100
                '<summary>',
2✔
101
                '</summary>',
2✔
102
                '</details>',
2✔
103
            ], '', $body);
2✔
104
        }
105
        $assignees = $config->getAssignees();
112✔
106
        $assignees_allowed = $this->getAssigneesAllowed();
112✔
107
        if (!$assignees_allowed) {
112✔
108
            // Log a message so it's possible to understand why.
109
            if (!empty($assignees)) {
99✔
110
                if ($is_private) {
1✔
111
                    $assignees = [];
1✔
112
                    $this->logger->log('info', 'Assignees on private projects are only allowed on the agency and enterprise plan, or when running violinist self-hosted. Configuration was detected for assignees, but will be ignored');
1✔
113
                } else {
NEW
114
                    $this->logger->log('info', 'Assignees on private projects are only allowed on the agency and enterprise plan. This project was detected to be public, so assignees will still apply even though a sufficient plan is not active');
×
115
                }
116
            }
117
        }
118
        return [
112✔
119
            'base'  => $default_branch,
112✔
120
            'head'  => $head,
112✔
121
            'title' => $title,
112✔
122
            'body'  => $body,
112✔
123
            'assignees' => $assignees,
112✔
124
        ];
112✔
125
    }
126

127
    private function getAssigneesAllowed() : bool
128
    {
129
        $assignees_allowed_roles = [
112✔
130
            'agency',
112✔
131
            'enterprise',
112✔
132
        ];
112✔
133
        if ($this->projectData && $this->projectData->getRoles()) {
112✔
134
            foreach ($this->projectData->getRoles() as $role) {
12✔
135
                if (in_array($role, $assignees_allowed_roles)) {
12✔
136
                    return true;
12✔
137
                }
138
            }
139
        }
140
        return $this->assigneesAllowed;
100✔
141
    }
142
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc