diff options
author | Phil Hughes <me@iamphill.com> | 2019-05-30 12:40:46 +0300 |
---|---|---|
committer | Igor Drozdov <idrozdov@gitlab.com> | 2019-06-17 13:04:51 +0300 |
commit | 8d002d1290fb02e6a6f2caa29a5762d484e208bd (patch) | |
tree | c0a1c7f697cd660808a1439134c0a52b35986320 | |
parent | e19577b5e7ceae26ac41f6faa5ea53c66f03e3ec (diff) |
Added last commit to tree entries in GraphQL API
-rw-r--r-- | app/assets/javascripts/repository/components/table/index.vue | 1 | ||||
-rw-r--r-- | app/assets/javascripts/repository/components/table/row.vue | 19 | ||||
-rw-r--r-- | app/assets/javascripts/repository/queries/getFiles.graphql | 4 | ||||
-rw-r--r-- | app/graphql/resolvers/last_commit_resolver.rb | 11 | ||||
-rw-r--r-- | app/graphql/types/commit_type.rb | 17 | ||||
-rw-r--r-- | app/graphql/types/tree/entry_type.rb | 1 |
6 files changed, 50 insertions, 3 deletions
diff --git a/app/assets/javascripts/repository/components/table/index.vue b/app/assets/javascripts/repository/components/table/index.vue index 0357a0e44c3..de237fcaab5 100644 --- a/app/assets/javascripts/repository/components/table/index.vue +++ b/app/assets/javascripts/repository/components/table/index.vue @@ -136,6 +136,7 @@ export default { :type="entry.type" :url="entry.webUrl" :lfs-oid="entry.lfsOid" + :commit="entry.commit" /> </template> </tbody> diff --git a/app/assets/javascripts/repository/components/table/row.vue b/app/assets/javascripts/repository/components/table/row.vue index e24a5e2c447..6f3e587db40 100644 --- a/app/assets/javascripts/repository/components/table/row.vue +++ b/app/assets/javascripts/repository/components/table/row.vue @@ -1,5 +1,7 @@ <script> import { GlBadge } from '@gitlab/ui'; +import { GlTooltipDirective } from '@gitlab/ui'; +import timeagoMixin from '~/vue_shared/mixins/timeago'; import { getIconName } from '../../utils/icon'; import getRefMixin from '../../mixins/get_ref'; @@ -7,7 +9,8 @@ export default { components: { GlBadge, }, - mixins: [getRefMixin], + directives: { GlTooltip: GlTooltipDirective }, + mixins: [timeagoMixin, getRefMixin], props: { id: { type: String, @@ -34,6 +37,10 @@ export default { type: String, required: false, default: null, + commit: { + type: Object, + required: false, + default: () => ({}), }, }, computed: { @@ -83,7 +90,13 @@ export default { @ <a href="#" class="commit-sha">{{ shortSha }}</a> </template> </td> - <td class="d-none d-sm-table-cell tree-commit"></td> - <td class="tree-time-ago text-right"></td> + <td class="d-none d-sm-table-cell tree-commit"> + <span class="str-truncated">{{ commit.message }}</span> + </td> + <td class="tree-time-ago text-right"> + <time v-gl-tooltip.top.viewport :datetime="commit.committedDate" :title="tooltipTitle(commit.committedDate)"> + {{ timeFormated(commit.committedDate) }} + </time> + </td> </tr> </template> diff --git a/app/assets/javascripts/repository/queries/getFiles.graphql b/app/assets/javascripts/repository/queries/getFiles.graphql index ef924fde556..a9e51ca0aa2 100644 --- a/app/assets/javascripts/repository/queries/getFiles.graphql +++ b/app/assets/javascripts/repository/queries/getFiles.graphql @@ -2,6 +2,10 @@ fragment TreeEntry on Entry { id flatPath type + commit { + message + committedDate + } } fragment PageInfo on PageInfo { diff --git a/app/graphql/resolvers/last_commit_resolver.rb b/app/graphql/resolvers/last_commit_resolver.rb new file mode 100644 index 00000000000..34f7c71fa08 --- /dev/null +++ b/app/graphql/resolvers/last_commit_resolver.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Resolvers + class LastCommitResolver < BaseResolver + def resolve + Gitlab::GitalyClient.allow_n_plus_1_calls do + Gitlab::Git::Commit.last_for_path(object.repository, object.commit_id, object.path) + end + end + end +end diff --git a/app/graphql/types/commit_type.rb b/app/graphql/types/commit_type.rb new file mode 100644 index 00000000000..3d8203473a7 --- /dev/null +++ b/app/graphql/types/commit_type.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true +module Types + class CommitType < BaseObject + graphql_name 'Commit' + + field :id, GraphQL::ID_TYPE, null: false + field :message, GraphQL::STRING_TYPE, null: false + + field :authored_date, Types::TimeType, null: false + field :author_name, GraphQL::STRING_TYPE, null: false + field :author_email, GraphQL::STRING_TYPE, null: false + + field :committed_date, Types::TimeType, null: false + field :committer_name, GraphQL::STRING_TYPE, null: false + field :committer_email, GraphQL::STRING_TYPE, null: false + end +end diff --git a/app/graphql/types/tree/entry_type.rb b/app/graphql/types/tree/entry_type.rb index d8e8642ddb8..b242fa02348 100644 --- a/app/graphql/types/tree/entry_type.rb +++ b/app/graphql/types/tree/entry_type.rb @@ -9,6 +9,7 @@ module Types field :type, Tree::TypeEnum, null: false field :path, GraphQL::STRING_TYPE, null: false field :flat_path, GraphQL::STRING_TYPE, null: false + field :commit, Types::CommitType, null: true, resolver: Resolvers::LastCommitResolver end end end |