@webship.co/workspace-openproject 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +183 -2
- package/ai/agents/openproject-site-builder.md +106 -0
- package/ai/agents/openproject-tester.md +118 -0
- package/ai/agents/openproject-work-package-worker.md +90 -0
- package/ai/commands/openproject-test.md +66 -0
- package/ai/prompts/openproject-build-and-test.md +28 -0
- package/ai/prompts/openproject-work-package-to-branch.md +24 -0
- package/ai/skills/openproject-scenarios/SKILL.md +74 -0
- package/ai/skills/openproject-scenarios/examples/roles.feature +17 -0
- package/ai/skills/openproject-scenarios/examples/session.feature +24 -0
- package/ai/skills/openproject-scenarios/examples/work-package.feature +17 -0
- package/commands/cmd-openproject-project.sh +31 -0
- package/commands/cmd-tools-openproject-cli.sh +24 -0
- package/config/plugin.openproject.settings.yml +29 -0
- package/config/settings.labels.yml +57 -0
- package/dist/src/index.d.ts +34 -0
- package/dist/src/index.js +60 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/tracker.d.ts +26 -0
- package/dist/src/lib/tracker.js +323 -0
- package/dist/src/lib/tracker.js.map +1 -0
- package/features/openproject-runtimes.feature +32 -0
- package/features/openproject.feature +53 -0
- package/package.json +118 -4
- package/scripts/args/arg-openproject-cli.sh +28 -0
- package/scripts/args/arg-openproject.sh +31 -0
- package/scripts/docker-compose.openproject.yaml +46 -0
- package/scripts/functions/fun-openproject.sh +590 -0
- package/scripts/openproject-serve.sh +17 -0
- package/scripts/openproject-site.rb +246 -0
- package/testing/site.feature +28 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# The Webship Workspace's OpenProject builder and tool, run with OpenProject's own Rails runner in the site's
|
|
4
|
+
# container, as OpenProject's user:
|
|
5
|
+
#
|
|
6
|
+
# bundle exec rails runner openproject-site.rb <verb>...
|
|
7
|
+
#
|
|
8
|
+
# accounts the accounts on the input (the base64 of a JSON list of login, mail, password, firstname, lastname,
|
|
9
|
+
# admin, role, action): made, or given back their name, password and status, with the first login done
|
|
10
|
+
# (no welcome dialog); with a role, a member of the sample project in it, without one a member of nothing
|
|
11
|
+
# there; with the action "lock", locked (it cannot log in; its work stays).
|
|
12
|
+
# content the sample content: the project "Webship site" with its work packages, its active sprint and a comment,
|
|
13
|
+
# each made where it is missing.
|
|
14
|
+
# tidy what a test run that was stopped half way left: its work packages ("Webship test …"), their time first.
|
|
15
|
+
# list the default accounts, and what the sample project holds.
|
|
16
|
+
# token an API token of the active account whose login is on the input, as "TOKEN <value>" (for --connect,
|
|
17
|
+
# which writes it to the dashboard's settings; never shown).
|
|
18
|
+
#
|
|
19
|
+
# Nothing secret comes on its command line: passwords and logins travel on the input.
|
|
20
|
+
|
|
21
|
+
require 'base64'
|
|
22
|
+
require 'json'
|
|
23
|
+
|
|
24
|
+
PROJECT_IDENTIFIER = 'webship-site'
|
|
25
|
+
PROJECT_NAME = 'Webship site'
|
|
26
|
+
TEST_PREFIX = 'Webship test'
|
|
27
|
+
DEFAULT_LOGINS = %w[owner member reader stranger].freeze
|
|
28
|
+
|
|
29
|
+
def say(text)
|
|
30
|
+
puts text
|
|
31
|
+
$stdout.flush
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Kernel#warn says nothing when $VERBOSE is nil, as it is in a runner of the production environment.
|
|
35
|
+
def fail_with(text)
|
|
36
|
+
$stderr.puts text
|
|
37
|
+
$stderr.flush
|
|
38
|
+
exit 1
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def admin_user
|
|
42
|
+
User.active.where(admin: true).order(:id).first || fail_with('No active administrator on the site.')
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def errors_of(result)
|
|
46
|
+
result.respond_to?(:errors) ? result.errors.full_messages.join('; ') : result.to_s
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# The sample project, made the first time; its modules and the types the step pack and the tracker use are enabled
|
|
50
|
+
# every time, where they are missing.
|
|
51
|
+
def ensure_project
|
|
52
|
+
project = Project.find_by(identifier: PROJECT_IDENTIFIER)
|
|
53
|
+
unless project
|
|
54
|
+
attributes = {
|
|
55
|
+
name: PROJECT_NAME, identifier: PROJECT_IDENTIFIER, public: false,
|
|
56
|
+
description: 'The sample project of a Webship Workspace site: its work packages, sprint and members are what the step pack and the tracker are tested on.'
|
|
57
|
+
}
|
|
58
|
+
# A project is one of the kinds of workspace since OpenProject 17 (project, program, portfolio).
|
|
59
|
+
attributes[:workspace_type] = 'project' if Project.respond_to?(:workspace_types)
|
|
60
|
+
result = Projects::CreateService.new(user: admin_user).call(**attributes)
|
|
61
|
+
fail_with("The project #{PROJECT_NAME} could not be made: #{errors_of(result)}") unless result.success?
|
|
62
|
+
project = result.result
|
|
63
|
+
say "project: #{PROJECT_NAME} (#{PROJECT_IDENTIFIER}) made"
|
|
64
|
+
end
|
|
65
|
+
available = OpenProject::AccessControl.available_project_modules.map(&:to_s)
|
|
66
|
+
modules = (project.enabled_module_names | %w[work_package_tracking backlogs costs board_view activity news]) & available
|
|
67
|
+
if modules.sort != project.enabled_module_names.sort
|
|
68
|
+
project.enabled_module_names = modules
|
|
69
|
+
project.save!
|
|
70
|
+
end
|
|
71
|
+
wanted = Type.where(name: ['Task', 'Bug', 'Feature', 'Milestone', 'User story', 'Epic']).to_a
|
|
72
|
+
if project.respond_to?(:project_types)
|
|
73
|
+
# OpenProject 17: a type is enabled in a project by a row of its own (with its variant, the type's own by default).
|
|
74
|
+
have = project.project_types.pluck(:type_id)
|
|
75
|
+
wanted.each { |type| project.project_types.create!(type_id: type.id) unless have.include?(type.id) }
|
|
76
|
+
elsif (wanted - project.types.to_a).any?
|
|
77
|
+
project.types = (project.types.to_a | wanted)
|
|
78
|
+
project.save!
|
|
79
|
+
end
|
|
80
|
+
project
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def role_named(name)
|
|
84
|
+
(defined?(ProjectRole) ? ProjectRole.find_by(name:) : nil) || Role.find_by(name:) || fail_with("No role #{name} on the site.")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# The account's membership of the sample project: in the role, or none.
|
|
88
|
+
def membership(project, user, role_name)
|
|
89
|
+
member = Member.find_by(project_id: project.id, user_id: user.id)
|
|
90
|
+
if role_name.to_s.empty?
|
|
91
|
+
if member
|
|
92
|
+
member.destroy
|
|
93
|
+
say " #{user.login}: no longer a member of #{PROJECT_NAME}"
|
|
94
|
+
end
|
|
95
|
+
return
|
|
96
|
+
end
|
|
97
|
+
role = role_named(role_name)
|
|
98
|
+
if member
|
|
99
|
+
member.role_ids = [role.id]
|
|
100
|
+
member.save!
|
|
101
|
+
else
|
|
102
|
+
Member.new(project:, principal: user, roles: [role]).save!
|
|
103
|
+
end
|
|
104
|
+
say " #{user.login}: #{role.name} of #{PROJECT_NAME}"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def accounts(rows)
|
|
108
|
+
project = rows.any? { |r| !r['role'].to_s.empty? } ? ensure_project : Project.find_by(identifier: PROJECT_IDENTIFIER)
|
|
109
|
+
rows.each do |r|
|
|
110
|
+
login = r['login'].to_s
|
|
111
|
+
fail_with('An account row has no login.') if login.empty?
|
|
112
|
+
user = User.find_by(login:)
|
|
113
|
+
if r['action'] == 'lock'
|
|
114
|
+
if user.nil?
|
|
115
|
+
say " #{login}: no such account"
|
|
116
|
+
elsif user.admin?
|
|
117
|
+
say " #{login}: an administrator, left as it is"
|
|
118
|
+
else
|
|
119
|
+
user.update!(status: :locked)
|
|
120
|
+
say " #{login}: locked"
|
|
121
|
+
end
|
|
122
|
+
next
|
|
123
|
+
end
|
|
124
|
+
user ||= User.new(login:)
|
|
125
|
+
user.mail = r['mail'].to_s
|
|
126
|
+
user.firstname = r['firstname'].to_s.empty? ? login.capitalize : r['firstname']
|
|
127
|
+
user.lastname = r['lastname'].to_s.empty? ? 'Test' : r['lastname']
|
|
128
|
+
user.admin = true if r['admin']
|
|
129
|
+
user.status = :active
|
|
130
|
+
user.language = 'en'
|
|
131
|
+
user.first_login = false
|
|
132
|
+
user.force_password_change = false
|
|
133
|
+
user.password = r['password']
|
|
134
|
+
user.password_confirmation = r['password']
|
|
135
|
+
fail_with("The account #{login} could not be saved: #{user.errors.full_messages.join('; ')}") unless user.save
|
|
136
|
+
say " #{login}: #{user.admin? ? 'administrator' : 'account'} ready (#{user.mail})"
|
|
137
|
+
membership(project, user, r['role']) if project && (r.key?('role') && !r['admin'])
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def create_work_package(project, by, type, subject, body, assignee: nil)
|
|
142
|
+
existing = WorkPackage.find_by(project_id: project.id, subject:)
|
|
143
|
+
return [existing, false] if existing
|
|
144
|
+
|
|
145
|
+
attrs = { project:, type:, subject:, description: body }
|
|
146
|
+
attrs[:assigned_to] = assignee if assignee
|
|
147
|
+
result = WorkPackages::CreateService.new(user: by).call(**attrs)
|
|
148
|
+
fail_with("The work package \"#{subject}\" could not be made: #{errors_of(result)}") unless result.success?
|
|
149
|
+
[result.result, true]
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def content
|
|
153
|
+
project = ensure_project
|
|
154
|
+
owner, member, stranger = %w[owner member stranger].map { |l| User.find_by(login: l) }
|
|
155
|
+
fail_with('The default accounts are not on the site: add them first (--add-users).') unless owner && member && stranger
|
|
156
|
+
|
|
157
|
+
status = Sprint.statuses.key?('active') ? 'active' : Sprint.statuses.keys.first
|
|
158
|
+
sprint = Sprint.find_by(project_id: project.id, name: 'Sprint 1') ||
|
|
159
|
+
Sprint.create!(project:, name: 'Sprint 1', start_date: Date.current, finish_date: Date.current + 11, status:)
|
|
160
|
+
task = Type.find_by(name: 'Task') || fail_with('No type Task on the site.')
|
|
161
|
+
bug = Type.find_by(name: 'Bug') || task
|
|
162
|
+
|
|
163
|
+
greeting, made = create_work_package(project, owner, task, 'The greeting script says Helo instead of Hello', <<~MD, assignee: member)
|
|
164
|
+
### Problem/Motivation
|
|
165
|
+
|
|
166
|
+
`bash greeting.sh World` prints `Helo, World!`.
|
|
167
|
+
|
|
168
|
+
### Proposed resolution
|
|
169
|
+
|
|
170
|
+
Print `Hello, World!`, and keep the usage line as it is.
|
|
171
|
+
MD
|
|
172
|
+
if made
|
|
173
|
+
greeting.update_column(:sprint_id, sprint.id)
|
|
174
|
+
progress = Status.find_by(name: 'In progress')
|
|
175
|
+
WorkPackages::UpdateService.new(user: owner, model: greeting.reload).call(status: progress) if progress
|
|
176
|
+
AddWorkPackageNoteService.new(user: owner, work_package: greeting.reload).call('The script is in the project\'s repository: `greeting.sh`.')
|
|
177
|
+
end
|
|
178
|
+
create_work_package(project, member, bug, 'The usage page spells greeting as greting', <<~MD)
|
|
179
|
+
### Problem/Motivation
|
|
180
|
+
|
|
181
|
+
The usage line of `greeting.sh` says "greting".
|
|
182
|
+
|
|
183
|
+
### Proposed resolution
|
|
184
|
+
|
|
185
|
+
Spell it "greeting".
|
|
186
|
+
MD
|
|
187
|
+
outside, made = create_work_package(project, owner, task, 'A work package opened by someone outside the project', <<~MD)
|
|
188
|
+
Please also print the date after the greeting.
|
|
189
|
+
MD
|
|
190
|
+
if made
|
|
191
|
+
# Opened by an account with no membership: the tracker treats it as from outside the project.
|
|
192
|
+
outside.update_column(:author_id, stranger.id)
|
|
193
|
+
outside.journals.order(:version).first&.update_column(:user_id, stranger.id)
|
|
194
|
+
end
|
|
195
|
+
say "content: #{PROJECT_NAME} holds #{WorkPackage.where(project_id: project.id).count} work packages, #{sprint.name} (#{sprint.status})"
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def tidy
|
|
199
|
+
admin = admin_user
|
|
200
|
+
left = WorkPackage.where('subject LIKE ?', "#{TEST_PREFIX}%").to_a
|
|
201
|
+
left.each do |wp|
|
|
202
|
+
TimeEntry.where(entity: wp).delete_all
|
|
203
|
+
result = WorkPackages::DeleteService.new(user: admin, model: wp).call
|
|
204
|
+
wp.destroy unless result.success?
|
|
205
|
+
end
|
|
206
|
+
say "tidy: #{left.size} work package(s) of a stopped test run removed"
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def list
|
|
210
|
+
project = Project.find_by(identifier: PROJECT_IDENTIFIER)
|
|
211
|
+
say 'Accounts:'
|
|
212
|
+
User.not_builtin.where(login: DEFAULT_LOGINS).or(User.not_builtin.where(admin: true)).order(:id).each do |u|
|
|
213
|
+
role = project && Member.find_by(project_id: project.id, user_id: u.id)&.roles&.map(&:name)&.join(', ')
|
|
214
|
+
say format(' %-12s %-28s %-8s %s', u.login, u.mail, u.status, u.admin? ? 'administrator' : (role.to_s.empty? ? 'no membership' : role))
|
|
215
|
+
end
|
|
216
|
+
return say("No project #{PROJECT_NAME} (#{PROJECT_IDENTIFIER}) yet: --sample-content adds it.") unless project
|
|
217
|
+
|
|
218
|
+
wps = WorkPackage.where(project_id: project.id)
|
|
219
|
+
say "#{PROJECT_NAME} (#{PROJECT_IDENTIFIER}): #{wps.count} work packages (#{wps.joins(:status).where(statuses: { is_closed: false }).count} open), " \
|
|
220
|
+
"#{Sprint.where(project_id: project.id).count} sprint(s), #{TimeEntry.where(project_id: project.id).count} time entries"
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# A new API token of the account, named for the workspace; the ones it made before for that account are revoked, so
|
|
224
|
+
# one token of the workspace's stays valid.
|
|
225
|
+
def token(login)
|
|
226
|
+
user = User.active.find_by(login:) || fail_with("No active account #{login} on the site.")
|
|
227
|
+
Token::API.where(user:).select { |t| t.respond_to?(:token_name) && t.token_name.to_s.start_with?('Webship Workspace') }.each(&:destroy)
|
|
228
|
+
made = Token::API.create!(user:, token_name: "Webship Workspace #{Time.now.utc.strftime('%Y-%m-%d %H:%M:%S')}")
|
|
229
|
+
puts "TOKEN #{made.plain_value}"
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
verbs = ARGV.dup
|
|
233
|
+
fail_with('A verb, please: accounts, content, tidy, list or token.') if verbs.empty?
|
|
234
|
+
verbs.each do |verb|
|
|
235
|
+
case verb
|
|
236
|
+
when 'accounts'
|
|
237
|
+
raw = $stdin.read.to_s.strip
|
|
238
|
+
fail_with('accounts reads the base64 of a JSON list on its input.') if raw.empty?
|
|
239
|
+
accounts(JSON.parse(Base64.decode64(raw)))
|
|
240
|
+
when 'content' then content
|
|
241
|
+
when 'tidy' then tidy
|
|
242
|
+
when 'list' then list
|
|
243
|
+
when 'token' then token($stdin.gets.to_s.strip)
|
|
244
|
+
else fail_with("Not a verb: #{verb} (accounts, content, tidy, list, token).")
|
|
245
|
+
end
|
|
246
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
@site
|
|
2
|
+
Feature: The work packages of the site
|
|
3
|
+
A first feature of an OpenProject site of the Webship Workspace, placed by the testing setup: a member logs in, reads
|
|
4
|
+
the sample project's work packages and sprint, and works a work package of its own, which goes after the scenario.
|
|
5
|
+
It passes on a site built with --install --add-users --sample-content; add your own features beside it.
|
|
6
|
+
|
|
7
|
+
Scenario: A member reads the sample project
|
|
8
|
+
Given I am a logged in user with the "member" user
|
|
9
|
+
When I open the work packages of the project "webship-site"
|
|
10
|
+
Then the work package list should show "The greeting script says Helo instead of Hello"
|
|
11
|
+
When I open the backlog of the project "webship-site"
|
|
12
|
+
Then the sprint "Sprint 1" should be "Active"
|
|
13
|
+
And the sprint "Sprint 1" should list the work package "The greeting script says Helo instead of Hello"
|
|
14
|
+
|
|
15
|
+
Scenario: A member works a work package of its own
|
|
16
|
+
Given there is a work package "Webship test site" in the project "webship-site"
|
|
17
|
+
And I am a logged in user with the "member" user
|
|
18
|
+
When I open the work package "Webship test site"
|
|
19
|
+
And I set the status of the work package to "In progress"
|
|
20
|
+
And I comment "Checked on the test site" on the work package
|
|
21
|
+
And I log "0.5" hours on the work package
|
|
22
|
+
Then the work package should show the comment "Checked on the test site" by "Member Test"
|
|
23
|
+
And the time spent on the work package should be "0.5h"
|
|
24
|
+
|
|
25
|
+
@js-off
|
|
26
|
+
Scenario: An account with no membership is refused the project
|
|
27
|
+
Given I am a logged in user with the "stranger" user
|
|
28
|
+
Then I should be refused the project "webship-site"
|