Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support community url and DCO for bot #33

Merged
merged 2 commits into from
Jun 1, 2023
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
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,8 @@ export NOTIFICATION_EXPLORE_URL=/explore
export NOTIFICATION_WECHAT_ACCOUNT_BIND_TEMPLATE_ID=OPENTM415757701
export NOTIFICATION_WECHAT_REPORT_GENERATE_TEMPLATE_ID=OPENTM407521893
export NOTIFICATION_WECHAT_REPORT_SUBSCRIPTION_UPDATE_TEMPLATE_ID=OPENTM412612104

# CI Bots
export BOT_NAME=compass-bot
export [email protected]

2 changes: 2 additions & 0 deletions app/controllers/concerns/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module Common
CELERY_SERVER = ENV.fetch('CELERY_SERVER') { 'http://localhost:8000' }
SUPPORT_DOMAINS = ['gitee.com', 'github.com', 'raw.githubusercontent.com']
SUPPORT_DOMAIN_NAMES = ['gitee', 'github']
BOT_NAME = ENV.fetch('BOT_NAME') { 'compass-bot' }
BOT_EMAIL = ENV.fetch('BOT_EMAIL') { '[email protected]' }
GITEE_REPO = ENV.fetch('GITEE_WORKFLOW_REPO')
GITHUB_REPO = ENV.fetch('GITHUB_WORKFLOW_REPO')
META_REPO = ENV.fetch('WORKFLOW_REPO_NAME') { 'compass-projects-information' }
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/concerns/gitee_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ def gitee_create_branch(branch_name, refs: 'main')
end

def gitee_post_file(path, message, content_base64, branch_name)
signed_off_message = message + "\n\nSigned-off-by: #{BOT_NAME} <#{BOT_EMAIL}>"
resp =
Faraday.post(
"#{GITEE_API_ENDPOINT}/repos/#{gitee_owner}/#{gitee_repo}/contents/#{path}",
{ message: message, content: content_base64, branch: branch_name, access_token: GITEE_TOKEN }.to_json,
{ message: signed_off_message, content: content_base64, branch: branch_name, access_token: GITEE_TOKEN }.to_json,
{ 'Content-Type' => 'application/json'}
)
case JSON.parse(resp.body).symbolize_keys
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/concerns/github_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ def github_create_ref(branch_name, sha)
end

def github_put_file(path, message, content_base64, branch_name)
signed_off_message = message + "\n\nSigned-off-by: #{BOT_NAME} <#{BOT_EMAIL}>"
resp =
RestClient::Request.new(
method: :put,
url: "#{GITHUB_API_ENDPOINT}/repos/#{github_owner}/#{github_repo}/contents/#{path}",
payload: { message: message, content: content_base64, branch: branch_name }.to_json,
payload: { message: signed_off_message, content: content_base64, branch: branch_name }.to_json,
headers: { 'Content-Type' => 'application/json' , 'Authorization' => "Bearer #{GITHUB_TOKEN}" },
proxy: PROXY
).execute
Expand Down
6 changes: 4 additions & 2 deletions app/graphql/mutations/create_project_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ class CreateProjectTask < BaseMutation
argument :project_name, String, required: true, description: 'project label for following repositories'
argument :project_types, [Input::ProjectTypeInput], required: true, description: 'project detail information'
argument :origin, String, required: true, description: "user's origin (gitee/github)"
argument :project_url, String, required: false, description: 'project homepage url'

def resolve(project_name:, project_types:, origin:)
def resolve(project_name:, project_types:, origin:, project_url: nil)
current_user = context[:current_user]
raise GraphQL::ExecutionError.new I18n.t('users.require_login') if current_user.blank?

Expand All @@ -19,6 +20,7 @@ def resolve(project_name:, project_types:, origin:)

yaml_template = {}
yaml_template['community_name'] = project_name
yaml_template['community_url'] = project_url if project_url
yaml_template['resource_types'] =
project_types.reduce({}) do |result, type|
result.merge({ type.type => { 'repo_urls' => type.repo_list } })
Expand Down Expand Up @@ -63,7 +65,7 @@ def resolve(project_name:, project_types:, origin:)
label: project_name,
level: 'community',
project_types: project_types,
extra: { username: username, origin: origin }
extra: { username: username, origin: origin, community_url: project_url }
}
).execute
OpenStruct.new(result.reverse_merge({ pr_url: nil, message: '', status: true, report_url: nil }))
Expand Down
1 change: 1 addition & 0 deletions app/graphql/types/community_overview_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Types
class CommunityOverviewType < Types::BaseObject
field :community_url, String
field :projects_count, Integer
field :trends, [Types::RepoType]
end
Expand Down
1 change: 1 addition & 0 deletions app/graphql/types/latest_metrics_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class LatestMetricsType < Types::BaseObject
field :organizations_activity_updated_at, GraphQL::Types::ISO8601DateTime, description: 'latest score of organizations activity metric model updated_at'
field :repos_count, Float, description: 'repositories count'
field :origin, String, description: 'repositories origin'
field :reference_url, String, description: 'repository or community reference url'
field :label, String, description: 'metric model object identification'
field :level, String, description: 'metric model object level'
end
Expand Down
9 changes: 9 additions & 0 deletions app/graphql/types/queries/base_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ def extract_repos_count(label, level)
end
end

def extract_label_reference(label, level)
if level == 'community'
project = ProjectTask.find_by(project_name: label)
JSON.parse(project.extra)['community_url'] rescue nil
else
label
end
end

def extract_name_and_full_path(label)
if label =~ /github\.com\/(.+)\/(.+)/
[$2, "#{$1}/#{$2}"]
Expand Down
3 changes: 3 additions & 0 deletions app/graphql/types/queries/community_overview_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CommunityOverviewQuery < BaseQuery

def resolve(label: nil, page: 1, per: 9, type: nil)
project = ProjectTask.find_by(project_name: label)
community_url = JSON.parse(project.extra)['community_url'] rescue nil
skeleton = Hash[Types::CommunityOverviewType.fields.keys.zip([])].symbolize_keys

result =
Expand All @@ -43,10 +44,12 @@ def resolve(label: nil, page: 1, per: 9, type: nil)
skeleton['trends'] += build_gitee_repo(resp2).map { |repo| repo_extander.(repo, type) }
end
skeleton['projects_count'] = repo_list.length
skeleton['community_url'] = community_url
skeleton
else
skeleton['projects_count'] = 0
skeleton['trends'] = []
skeleton['community_url'] = community_url
skeleton
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/graphql/types/queries/latest_metrics_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def resolve(label: nil, level: 'repo')
label = normalize_label(label)
origin = extract_repos_source(label, level)
repos_count = extract_repos_count(label, level)
reference_url = extract_label_reference(label, level)

result = {}
[ActivityMetric, CommunityMetric, CodequalityMetric, GroupActivityMetric].map do |metric|
Expand All @@ -22,6 +23,7 @@ def resolve(label: nil, level: 'repo')
skeleton = skeleton.merge(Hash[keys.map(&:underscore).zip([])].symbolize_keys)
skeleton['origin'] = origin
skeleton['repos_count'] = repos_count
skeleton['reference_url'] = reference_url
OpenStruct.new(skeleton.merge(result))
end

Expand Down
7 changes: 7 additions & 0 deletions app/services/analyze_group_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,20 @@ def submit_task_status

if repo_task.present?
repo_task.update(status: task_resp['status'], task_id: task_resp['id'])
if repo_task.extra.present?
extra = JSON.parse(repo_task.extra) rescue {}
if @raw_yaml['community_url'] && extra['community_url'] != @raw_yaml['community_url']
repo_task.update(extra: extra.merge({community_url: @raw_yaml['community_url']}).to_json)
end
end
else
ProjectTask.create(
task_id: task_resp['id'],
remote_url: @yaml_url,
status: task_resp['status'],
payload: payload.to_json,
level: @level,
extra: ({community_url: @raw_yaml['community_url']}.to_json if @raw_yaml['community_url'] rescue nil),
project_name: @project_name
)
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/export_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def execute
return
end

output, status = Open3.capture2("git commit -m 'Update at #{DateTime.now.to_s}'", :chdir=>chdir)
output, status = Open3.capture2("git commit -s -m 'Update at #{DateTime.now.to_s}'", :chdir=>chdir)
if !status.success?
job_logger.error "failed to git commit, error: #{output}"
return
Expand Down
1 change: 1 addition & 0 deletions app/services/pull_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def update_workflow
branch = "#{DateTime.now.strftime('%Y%m%d%H%M%S')}-#{@label.gsub('/', '-')}"
project = {}
project['community_name'] = @label
project['community_url'] = @extra[:community_url] if @extra[:community_url]
project['resource_types'] =
@project_types.reduce({}) do |result, type|
result.merge({ type.type => { 'repo_urls' => type.repo_list } })
Expand Down